-
Notifications
You must be signed in to change notification settings - Fork 0
ci: publish Snap edge builds #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| name: Snap | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - ".github/workflows/snap.yml" | ||
| - "snap/**" | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - ".github/workflows/snap.yml" | ||
| - "snap/**" | ||
| workflow_dispatch: | ||
| inputs: | ||
| publish_edge: | ||
| description: "Publish successful main-branch builds to edge. Stable promotion stays manual." | ||
| default: false | ||
| required: true | ||
| type: boolean | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: snap-${{ github.ref }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| build: | ||
| name: Build snap (${{ matrix.arch }}) | ||
| runs-on: ${{ matrix.runner }} | ||
| timeout-minutes: 90 | ||
| env: | ||
| SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_STORE_CREDENTIALS }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - arch: amd64 | ||
| runner: ubuntu-24.04 | ||
| - arch: arm64 | ||
| runner: ubuntu-24.04-arm | ||
|
|
||
| steps: | ||
| - name: Check out SDK | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
|
|
||
| - name: Build snap | ||
| id: build | ||
| uses: snapcore/action-build@3bdaa03e1ba6bf59a65f84a751d943d549a54e79 # v1 | ||
| with: | ||
| path: snap | ||
| snapcraft-args: --build-for=${{ matrix.arch }} | ||
|
|
||
| - name: Upload snap artefact | ||
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | ||
| with: | ||
| name: sendmux-snap-${{ matrix.arch }} | ||
| path: ${{ steps.build.outputs.snap }} | ||
| retention-days: 30 | ||
|
|
||
| - name: Require Snap Store credentials | ||
| if: >- | ||
| ${{ | ||
| github.ref == 'refs/heads/main' && | ||
| (github.event_name == 'push' || inputs.publish_edge == true) && | ||
| env.SNAPCRAFT_STORE_CREDENTIALS == '' | ||
| }} | ||
| run: | | ||
| echo "::error::SNAPCRAFT_STORE_CREDENTIALS is required to publish Sendmux snap builds to edge." | ||
| exit 1 | ||
|
|
||
| - name: Publish snap to edge | ||
| if: >- | ||
| ${{ | ||
| github.ref == 'refs/heads/main' && | ||
| (github.event_name == 'push' || inputs.publish_edge == true) && | ||
| env.SNAPCRAFT_STORE_CREDENTIALS != '' | ||
| }} | ||
| uses: snapcore/action-publish@214b86e5ca036ead1668c79afb81e550e6c54d40 # v1.2.0 | ||
| env: | ||
| SNAPCRAFT_STORE_CREDENTIALS: ${{ env.SNAPCRAFT_STORE_CREDENTIALS }} | ||
| with: | ||
| snap: ${{ steps.build.outputs.snap }} | ||
| release: edge | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| import assert from "node:assert/strict"; | ||
| import { readFileSync } from "node:fs"; | ||
|
|
||
| const workflowPath = ".github/workflows/snap.yml"; | ||
| const workflow = readFileSync(workflowPath, "utf8"); | ||
| const snapReadme = readFileSync("snap/README.md", "utf8"); | ||
|
|
||
| assert.match(workflow, /^name: Snap$/m, "Snap workflow must have a stable name."); | ||
| assert.match(workflow, /pull_request:[\s\S]*?paths:/, "PR builds must be limited to Snap-related paths."); | ||
| assert.match(workflow, /push:[\s\S]*?branches:[\s\S]*?- main/, "Main pushes must run the Snap workflow."); | ||
| assert.match(workflow, /workflow_dispatch:/, "Snap workflow must support manual build runs."); | ||
| assert.match(workflow, /permissions:[\s\S]*?contents: read/, "Snap workflow must use read-only repository permissions."); | ||
| assert.match( | ||
| workflow, | ||
| /concurrency:[\s\S]*?group: snap-\$\{\{ github\.ref \}\}[\s\S]*?cancel-in-progress: false/, | ||
| "Snap workflow must serialise per ref without cancelling in-flight store uploads.", | ||
| ); | ||
| assert.match(workflow, /ubuntu-24\.04-arm/, "Snap workflow must include a native arm64 runner."); | ||
| assert.match(workflow, /- arch: amd64/, "Snap workflow must explicitly include amd64 in the build matrix."); | ||
| assert.match(workflow, /- arch: arm64/, "Snap workflow must explicitly include arm64 in the build matrix."); | ||
| assert.match( | ||
| workflow, | ||
| /snapcraft-args: --build-for=\$\{\{ matrix\.arch \}\}/, | ||
| "Snap workflow must pass the selected matrix architecture to Snapcraft.", | ||
| ); | ||
| assert.match(workflow, /path: snap/, "Snapcraft action must build from the snap project directory."); | ||
| assert.match( | ||
| workflow, | ||
| /SNAPCRAFT_STORE_CREDENTIALS: \$\{\{ secrets\.SNAPCRAFT_STORE_CREDENTIALS \}\}/, | ||
| "Snap Store credentials must come from the repository secret expected by snapcore/action-publish.", | ||
| ); | ||
| assert.match(workflow, /release: edge/, "Snap workflow must publish only to edge."); | ||
| assert.doesNotMatch(workflow, /release: stable/, "Stable Snap promotion must remain manual."); | ||
|
|
||
| const publishStep = stepBlock("Publish snap to edge"); | ||
| assert.match( | ||
| publishStep.text, | ||
| /github\.ref == 'refs\/heads\/main'/, | ||
| "Snap publishing must be limited to the main branch.", | ||
| ); | ||
| assert.match( | ||
| publishStep.text, | ||
| /github\.event_name == 'push' \|\| inputs\.publish_edge == true/, | ||
| "Snap publishing must happen on main pushes or explicit manual publish runs.", | ||
| ); | ||
| assert.match( | ||
| publishStep.text, | ||
| /env\.SNAPCRAFT_STORE_CREDENTIALS != ''/, | ||
| "Snap publishing must fail closed when store credentials are absent.", | ||
| ); | ||
|
|
||
| assert.match( | ||
| snapReadme, | ||
| /--acls=package_access,package_push,package_update,package_release/, | ||
| "Snap credential docs must keep --acls joined with its value to avoid shell line-break mistakes.", | ||
| ); | ||
| assert.match( | ||
| snapReadme, | ||
| /test -s "\$secret_file"/, | ||
| "Snap credential docs must prove the exported login file is non-empty before setting the GitHub secret.", | ||
| ); | ||
| assert.match( | ||
| snapReadme, | ||
| /gh secret list --repo Sendmux\/sendmux-sdk/, | ||
| "Snap credential docs must require verifying the GitHub secret update timestamp.", | ||
| ); | ||
|
|
||
| console.log("Snap workflow tests passed."); | ||
|
|
||
| function stepBlock(name) { | ||
| const pattern = new RegExp(`^ - name: ${escapeRegExp(name)}\\n`, "m"); | ||
| const match = pattern.exec(workflow); | ||
| assert(match, `Missing Snap workflow step: ${name}`); | ||
|
|
||
| const start = match.index; | ||
| const next = workflow.slice(start + match[0].length).search(/^ - name: /m); | ||
| const end = next === -1 ? workflow.length : start + match[0].length + next; | ||
|
|
||
| return { | ||
| text: workflow.slice(start, end), | ||
| }; | ||
| } | ||
|
|
||
| function escapeRegExp(value) { | ||
| return value.replaceAll(/[.*+?^${}()|[\]\\]/g, "\\$&"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this secret is defined at job scope, every step receives
SNAPCRAFT_STORE_CREDENTIALS, including the Snapcraft build that runs PR-controlledsnap/**contents. For same-repository PRs or any merged change tosnap/snapcraft.yaml, anoverride-build/build script can read and exfiltrate the store login before the publish-onlyifguard is evaluated, so the credential should be passed only to the publish/credential-check path rather than the whole job.Useful? React with 👍 / 👎.