-
Notifications
You must be signed in to change notification settings - Fork 345
178 lines (151 loc) · 5.59 KB
/
main.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# This file lints the code, runs tests, builds a package and then deploys it.
# The following secrets need to be set:
# - “CLOUDSMITH_API_KEY” for pushing built package to Cloudsmith
# - “CACHIX_AUTH_TOKEN” for uploading built Nix packages to Cachix
name: CI
on:
pull_request:
push:
env:
COMPOSER_FLAGS: "--ansi --no-interaction --no-progress --no-suggest --prefer-dist"
jobs:
tests:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-22.04
strategy:
matrix:
# Other backends run only for single PHP version to reduce the CI costs.
storage:
- 'sqlite'
php:
- '8.3'
- '8.2'
- '8.1'
- '8.0'
- '7.4'
include:
- php: '7.4'
phpstan: true
cs_fixer: true
check_client: true
- php: '8.2'
storage: mysql
- php: '8.2'
storage: postgresql
name: 'Check with PHP ${{ matrix.php }} and ${{ matrix.storage }} storage backend'
steps:
- uses: actions/checkout@v3
- name: Install Nix
uses: cachix/install-nix-action@v20
- name: Set up Nix cache
uses: cachix/cachix-action@v12
with:
name: fossar
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Update flake.nix to match the current CI job from matrix
run: |
sed -i 's/matrix.phpPackage = "php";/matrix.phpPackage = builtins.replaceStrings ["."] [""] "php${{ matrix.php }}";/' flake.nix
sed -i 's/matrix.storage = "all";/matrix.storage = "${{ matrix.storage }}";/' flake.nix
- name: Cache Node modules
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"
- uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install dependencies
run: nix-shell --run 'npm run install-dependencies'
- name: Check front-end code
if: matrix.check_client
run: nix-shell --run 'npm run check:client'
- name: Check syntax of back-end code
run: nix-shell --run 'npm run lint:server'
- name: Lint back-end code
if: matrix.cs_fixer
run: nix-shell --run 'npm run cs:server'
- name: Run unit tests
run: nix-shell --run 'npm run test:server'
- name: Analyse back-end code
if: matrix.phpstan
run: nix-shell --run 'npm run analyse:server'
- name: Run integration tests
run: SELFOSS_TEST_STORAGE_BACKEND=${{ matrix.storage }} nix-shell --run 'npm run test:integration'
deploy:
name: 'Upload artefacts'
runs-on: ubuntu-22.04
needs:
- tests
steps:
- uses: actions/checkout@v3
- name: Install Nix
uses: cachix/install-nix-action@v20
- name: Set up Nix cache
uses: cachix/cachix-action@v12
with:
name: fossar
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- name: Cache Node modules
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"
- uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Build a zipball
id: zipball
run: |
nix-shell --run 'npm run dist'
echo "file_name=$(echo selfoss-*.zip)" >> "$GITHUB_OUTPUT"
echo "version=$(echo selfoss-*.zip | sed -e 's/^selfoss-//' -e 's/\.zip$//')" >> "$GITHUB_OUTPUT"
- name: Upload the zipball to GitHub
uses: actions/upload-artifact@v3
with:
name: ${{ steps.zipball.outputs.file_name }}
if-no-files-found: error
path: ${{ steps.zipball.outputs.file_name }}
- name: Upload the zipball to Cloudsmith
uses: jtojnar/action@feature-tags
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
with:
api-key: ${{ secrets.CLOUDSMITH_API_KEY }}
command: "push"
format: "raw"
owner: "fossar"
repo: "selfoss-git"
file: ${{ steps.zipball.outputs.file_name }}
name: selfoss.zip
version: ${{ steps.zipball.outputs.version }}
tags: version:latest
- name: Prepare a changelog
run: |
echo "changelog_text<<CHANGES_EOF" >> $GITHUB_ENV
sed '1,/^## /d;/^## /Q' NEWS.md >> $GITHUB_ENV
echo "CHANGES_EOF" >> $GITHUB_ENV
- name: Create a release
uses: softprops/[email protected]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body: ${{ env.changelog_text }}
files: ${{ steps.zipball.outputs.file_name }}