|
| 1 | +name: "Snapcraft" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: &inputs |
| 6 | + version: |
| 7 | + description: "Build Version" |
| 8 | + type: string |
| 9 | + required: true |
| 10 | + version-file: |
| 11 | + description: "Version File" |
| 12 | + type: string |
| 13 | + default: "src/*/_version.py" |
| 14 | + snap-file: |
| 15 | + description: "Snap File" |
| 16 | + type: string |
| 17 | + default: "snap/snapcraft.yaml" |
| 18 | + workflow_dispatch: |
| 19 | + inputs: *inputs |
| 20 | + |
| 21 | +jobs: |
| 22 | + snapcraft: |
| 23 | + name: "Snapcraft - ${{ matrix.os }}" |
| 24 | + runs-on: ${{ matrix.os }} |
| 25 | + timeout-minutes: 10 |
| 26 | + strategy: |
| 27 | + fail-fast: false |
| 28 | + matrix: |
| 29 | + os: [ubuntu-latest, ubuntu-24.04-arm] |
| 30 | + |
| 31 | + permissions: |
| 32 | + contents: read |
| 33 | + |
| 34 | + env: |
| 35 | + SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_STORE_CREDENTIALS }} |
| 36 | + |
| 37 | + steps: |
| 38 | + - name: "Checkout" |
| 39 | + uses: actions/checkout@v6 |
| 40 | + |
| 41 | + - name: "Debug event.json" |
| 42 | + continue-on-error: true |
| 43 | + run: cat "${GITHUB_EVENT_PATH}" |
| 44 | + - name: "Debug CTX github" |
| 45 | + continue-on-error: true |
| 46 | + env: |
| 47 | + GITHUB_CTX: ${{ toJSON(github) }} |
| 48 | + run: echo "$GITHUB_CTX" |
| 49 | + - name: "Debug Environment" |
| 50 | + continue-on-error: true |
| 51 | + run: env |
| 52 | + |
| 53 | + - name: "Update Version" |
| 54 | + uses: justalemon/VersionPatcher@master |
| 55 | + with: |
| 56 | + version: ${{ inputs.version }} |
| 57 | + initpy-files: ${{ inputs.version-file }} |
| 58 | + |
| 59 | + - name: "Debug Version" |
| 60 | + continue-on-error: true |
| 61 | + run: | |
| 62 | + cat ${{ inputs.version-file }} |
| 63 | +
|
| 64 | + # https://documentation.ubuntu.com/snapcraft/stable/how-to/crafting/configure-package-information/#configure-package-information |
| 65 | + - name: "Update Snap Version" |
| 66 | + uses: mikefarah/yq@master |
| 67 | + with: |
| 68 | + cmd: yq -i '.version = "${{ inputs.version }}"' '${{ inputs.snap-file }}' |
| 69 | + |
| 70 | + - name: "Debug Snap Version" |
| 71 | + continue-on-error: true |
| 72 | + run: | |
| 73 | + cat "${{ inputs.snap-file }}" |
| 74 | +
|
| 75 | + - name: "Snap Build" |
| 76 | + id: build |
| 77 | + uses: snapcore/action-build@v1 |
| 78 | + with: |
| 79 | + snapcraft-args: "--verbosity verbose" |
| 80 | + |
| 81 | + - name: "Stat Snap" |
| 82 | + continue-on-error: true |
| 83 | + run: | |
| 84 | + results="$(stat ${{ steps.build.outputs.snap }})" |
| 85 | + echo "::group::results" |
| 86 | + echo "${results}" |
| 87 | + echo "::endgroup::" |
| 88 | + md="Snap: \`${{ steps.build.outputs.snap }}\`\n\`\`\`text\n${results}\n\`\`\`" |
| 89 | + echo -e "${md}" >> "$GITHUB_STEP_SUMMARY" |
| 90 | +
|
| 91 | + - name: "Upload to Actions" |
| 92 | + if: ${{ github.event_name != 'release' }} |
| 93 | + uses: actions/upload-artifact@v5 |
| 94 | + with: |
| 95 | + name: snap |
| 96 | + path: ${{ steps.build.outputs.snap }} |
| 97 | + |
| 98 | + - name: "Upload Release" |
| 99 | + if: ${{ github.event_name == 'release' }} |
| 100 | + uses: cssnr/upload-release-action@latest |
| 101 | + with: |
| 102 | + files: ${{ steps.build.outputs.snap }} |
| 103 | + |
| 104 | + - name: "Snap Publish" |
| 105 | + uses: snapcore/action-publish@v1 |
| 106 | + with: |
| 107 | + snap: ${{ steps.build.outputs.snap }} |
| 108 | + release: stable |
| 109 | + |
| 110 | + - name: "Send Failure Notification" |
| 111 | + if: ${{ failure() }} |
| 112 | + uses: sarisia/actions-status-discord@b8381b25576cb341b2af39926ab42c5056cc44ed # v1.15.5 |
| 113 | + with: |
| 114 | + webhook: ${{ secrets.DISCORD_WEBHOOK }} |
| 115 | + description: ${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }} |
0 commit comments