|
3 | 3 | push: |
4 | 4 | branches: |
5 | 5 | - main |
| 6 | + # Release flavor is derived from the tag suffix in the deploy job. Convention: prefix tags |
| 7 | + # with "v" (bare X.Y.Z is still accepted for backward compatibility). |
6 | 8 | tags: |
7 | | - - '*.*.*' # semver, will override latest |
8 | | - - '*-preview' # preview, won't override latest |
| 9 | + - '*.*.*' # stable semver (e.g. v1.2.3): published and marked "Latest" |
| 10 | + - '*-preview' # pre-release (e.g. v1.2.3-preview): published, never "Latest" |
| 11 | + - '*-draft' # draft (e.g. v1.2.3-draft): unpublished for review, never "Latest" |
9 | 12 | pull_request: |
10 | 13 | branches: |
11 | 14 | - main |
12 | 15 | workflow_dispatch: # Allow manual trigger |
13 | 16 |
|
| 17 | +# Least privilege by default; the deploy job elevates it explicitly. |
14 | 18 | permissions: |
15 | | - contents: write |
16 | | - packages: write |
| 19 | + contents: read |
| 20 | + |
| 21 | +# Cancel superseded runs on the same ref, but only for pull requests — never abort an in-flight |
| 22 | +# push to main or a tag (which may be mid-release). |
| 23 | +concurrency: |
| 24 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 25 | + cancel-in-progress: ${{ github.event_name == 'pull_request' }} |
17 | 26 |
|
18 | 27 | jobs: |
19 | 28 | lint: |
20 | 29 | runs-on: ubuntu-latest |
21 | 30 | timeout-minutes: 5 |
22 | 31 | steps: |
23 | | - - uses: actions/checkout@v4 |
24 | | - |
25 | | - - uses: actions/setup-node@v4 |
| 32 | + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
| 33 | + with: |
| 34 | + persist-credentials: false |
| 35 | + - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 |
26 | 36 | with: |
27 | 37 | node-version-file: .nvmrc |
28 | | - cache: yarn |
29 | | - |
30 | | - - run: yarn install --frozen-lockfile |
31 | | - |
| 38 | + cache: npm |
| 39 | + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 |
| 40 | + with: |
| 41 | + go-version-file: go.mod |
| 42 | + - run: npm ci |
32 | 43 | - name: Lint sources |
33 | 44 | run: | |
34 | 45 | make lint |
35 | | - yarn lint |
| 46 | + npm run lint |
36 | 47 |
|
37 | 48 | test: |
38 | 49 | runs-on: ubuntu-latest |
39 | 50 | timeout-minutes: 5 |
40 | 51 | steps: |
41 | | - - uses: actions/checkout@v4 |
| 52 | + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
42 | 53 | with: |
43 | | - fetch-depth: 0 |
44 | | - |
45 | | - - uses: actions/setup-node@v4 |
| 54 | + fetch-depth: 0 # SonarCloud needs the full history for blame/coverage |
| 55 | + persist-credentials: false |
| 56 | + - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 |
46 | 57 | with: |
47 | 58 | node-version-file: .nvmrc |
48 | | - cache: yarn |
49 | | - |
50 | | - |
51 | | - - name: Setup Go environment |
52 | | - uses: actions/setup-go@v5 |
| 59 | + cache: npm |
| 60 | + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 |
53 | 61 | with: |
54 | | - go-version: stable |
55 | | - |
56 | | - - run: yarn install --frozen-lockfile |
57 | | - |
| 62 | + go-version-file: go.mod |
| 63 | + - run: npm ci |
58 | 64 | - name: Execute tests |
59 | 65 | run: | |
60 | 66 | make test |
61 | 67 | make test-integration |
62 | | - yarn test |
| 68 | + npm test |
63 | 69 | make coverage |
64 | | -
|
65 | 70 | - name: SonarCloud Scan |
66 | | - uses: sonarsource/sonarcloud-github-action@master |
| 71 | + uses: SonarSource/sonarqube-scan-action@22918119ff8e1ca75a623e15c8296b6ea4fbe28f # v8.2.1 |
67 | 72 | continue-on-error: true |
68 | 73 | env: |
69 | 74 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
70 | 75 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
71 | 76 |
|
72 | | - build: |
| 77 | + e2e: |
73 | 78 | runs-on: ubuntu-latest |
74 | | - timeout-minutes: 5 |
| 79 | + timeout-minutes: 10 |
75 | 80 | steps: |
76 | | - - uses: actions/checkout@v4 |
77 | | - |
78 | | - - id: extract_ref |
79 | | - run: echo ::set-output name=GIT_REF::$(echo ${GITHUB_REF##*/}) |
80 | | - |
81 | | - - uses: actions/setup-node@v4 |
| 81 | + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
| 82 | + with: |
| 83 | + persist-credentials: false |
| 84 | + - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 |
82 | 85 | with: |
83 | 86 | node-version-file: .nvmrc |
84 | | - cache: yarn |
85 | | - |
86 | | - - name: Setup Go environment |
87 | | - uses: actions/setup-go@v5 |
| 87 | + cache: npm |
| 88 | + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 |
| 89 | + with: |
| 90 | + go-version-file: go.mod |
| 91 | + - run: npm ci |
| 92 | + - name: Install Playwright browser |
| 93 | + run: npx playwright install --with-deps chromium |
| 94 | + - name: Run Playwright non-regression suite |
| 95 | + run: make test-e2e |
| 96 | + |
| 97 | + security: |
| 98 | + runs-on: ubuntu-latest |
| 99 | + timeout-minutes: 10 |
| 100 | + steps: |
| 101 | + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
| 102 | + with: |
| 103 | + persist-credentials: false |
| 104 | + - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 |
88 | 105 | with: |
89 | | - go-version: stable |
| 106 | + node-version-file: .nvmrc |
| 107 | + cache: npm |
| 108 | + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 |
| 109 | + with: |
| 110 | + go-version-file: go.mod |
| 111 | + # Audit only the dependencies that ship in the client bundle (dev tooling isn't served), and |
| 112 | + # fail only on high/critical advisories. |
| 113 | + - name: Audit frontend dependencies (npm) |
| 114 | + run: npm audit --omit=dev --audit-level=high |
| 115 | + # govulncheck reports only vulnerabilities actually reachable from the code, so it's low-noise |
| 116 | + # and safe to gate on. |
| 117 | + - name: Scan backend dependencies (govulncheck) |
| 118 | + run: go run golang.org/x/vuln/cmd/govulncheck@latest ./... |
90 | 119 |
|
91 | | - - run: yarn install --frozen-lockfile |
| 120 | + build: |
| 121 | + runs-on: ubuntu-latest |
| 122 | + timeout-minutes: 10 |
| 123 | + steps: |
| 124 | + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
| 125 | + with: |
| 126 | + persist-credentials: false |
| 127 | + - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 |
| 128 | + with: |
| 129 | + node-version-file: .nvmrc |
| 130 | + cache: npm |
| 131 | + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 |
| 132 | + with: |
| 133 | + go-version-file: go.mod |
92 | 134 |
|
93 | | - - name: Build |
| 135 | + # Every run assembles the native image and smoke-tests it (proves the Dockerfile + embedded |
| 136 | + # UI still work). Only tag builds also cross-compile the release binaries + tarball, which the |
| 137 | + # deploy job packages into the multi-arch image and the GitHub release. |
| 138 | + - name: Build image (+ release binaries on tags) and smoke-test |
| 139 | + env: |
| 140 | + VERSION: ${{ github.ref_name }} |
94 | 141 | run: | |
95 | | - make VERSION=${{ steps.extract_ref.outputs.GIT_REF }} RELEASE=1 release |
96 | | - make VERSION=${{ steps.extract_ref.outputs.GIT_REF }} build-docker |
97 | | - make VERSION=${{ steps.extract_ref.outputs.GIT_REF }} start-docker |
| 142 | + targets="build-docker start-docker smoke-docker" |
| 143 | + [[ "$GITHUB_REF" == refs/tags/* ]] && targets="release $targets" |
| 144 | + make VERSION="$VERSION" RELEASE=1 $targets |
98 | 145 |
|
99 | | - - if: startsWith(github.ref, 'refs/tags/') |
100 | | - uses: actions/upload-artifact@v4 |
| 146 | + - name: Upload release artifacts |
| 147 | + if: startsWith(github.ref, 'refs/tags/') |
| 148 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
101 | 149 | with: |
102 | | - name: smocker-bin |
103 | | - path: ./build/smocker.tar.gz |
| 150 | + name: smocker-dist |
| 151 | + path: | |
| 152 | + build/smocker.tar.gz |
| 153 | + build/smocker-* |
104 | 154 |
|
105 | 155 | deploy: |
106 | | - needs: [lint, test, build] |
| 156 | + needs: [lint, test, build, e2e, security] |
107 | 157 | if: startsWith(github.ref, 'refs/tags/') |
108 | 158 | runs-on: ubuntu-latest |
109 | 159 | timeout-minutes: 10 |
| 160 | + # Elevated only here: push the image to GHCR and publish the GitHub release. |
| 161 | + permissions: |
| 162 | + contents: write |
| 163 | + packages: write |
110 | 164 | steps: |
111 | | - - uses: actions/checkout@v4 |
112 | | - |
113 | | - - id: extract_ref |
114 | | - run: echo ::set-output name=GIT_REF::$(echo ${GITHUB_REF##*/}) |
| 165 | + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
| 166 | + with: |
| 167 | + persist-credentials: false |
115 | 168 |
|
116 | | - - uses: actions/download-artifact@v4 |
| 169 | + - id: release_flags |
| 170 | + name: Derive the release flavor from the tag suffix |
| 171 | + env: |
| 172 | + REF: ${{ github.ref_name }} |
| 173 | + run: | |
| 174 | + draft=false |
| 175 | + prerelease=false |
| 176 | + make_latest=true |
| 177 | + if [[ "$REF" == *-draft ]]; then |
| 178 | + draft=true # unpublished, editable on GitHub before release |
| 179 | + make_latest=false |
| 180 | + elif [[ "$REF" == *-* ]]; then |
| 181 | + prerelease=true # e.g. -preview / -rc: published but never "Latest" |
| 182 | + make_latest=false |
| 183 | + fi |
| 184 | + { |
| 185 | + echo "draft=$draft" |
| 186 | + echo "prerelease=$prerelease" |
| 187 | + echo "make_latest=$make_latest" |
| 188 | + } >> "$GITHUB_OUTPUT" |
| 189 | +
|
| 190 | + # The pre-built binaries (+ tarball) from the build job; the image is assembled from them. |
| 191 | + - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
117 | 192 | with: |
118 | | - name: smocker-bin |
| 193 | + name: smocker-dist |
119 | 194 | path: ./build |
120 | 195 |
|
121 | | - - run: cd build && tar -xvf smocker.tar.gz |
122 | | - |
123 | 196 | - name: Docker login |
124 | | - uses: docker/login-action@v3 |
| 197 | + uses: docker/login-action@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # v4.4.0 |
125 | 198 | with: |
126 | 199 | registry: ghcr.io |
127 | 200 | username: ${{ github.actor }} |
128 | 201 | password: ${{ secrets.GITHUB_TOKEN }} |
129 | 202 |
|
130 | | - - name: Set up QEMU |
131 | | - uses: docker/setup-qemu-action@v3 |
132 | | - |
| 203 | + # No QEMU: the image only packages the pre-built binaries (COPY-only target stages). |
133 | 204 | - name: Set up Docker Buildx |
134 | | - uses: docker/setup-buildx-action@v3 |
| 205 | + uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0 |
135 | 206 |
|
136 | 207 | - name: Deploy on Docker registry |
137 | | - run: make VERSION=${{ steps.extract_ref.outputs.GIT_REF }} deploy-docker |
| 208 | + env: |
| 209 | + VERSION: ${{ github.ref_name }} |
| 210 | + run: make VERSION="$VERSION" deploy-docker |
138 | 211 |
|
139 | 212 | - name: Deploy on GitHub releases |
140 | | - uses: softprops/action-gh-release@v2 |
| 213 | + uses: softprops/action-gh-release@3d0d9888cb7fd7b750713d6e236d1fcb99157228 # v3.0.2 |
141 | 214 | with: |
142 | | - files: build/smocker.tar.gz |
| 215 | + files: | |
| 216 | + build/smocker.tar.gz |
| 217 | + build/smocker-* |
143 | 218 | token: ${{ secrets.GITHUB_TOKEN }} |
| 219 | + draft: ${{ steps.release_flags.outputs.draft }} |
| 220 | + prerelease: ${{ steps.release_flags.outputs.prerelease }} |
| 221 | + make_latest: ${{ steps.release_flags.outputs.make_latest }} |
0 commit comments