|
| 1 | +on: |
| 2 | + workflow_call: |
| 3 | + inputs: |
| 4 | + project-name: |
| 5 | + description: 'Name of the application to build (e.g. qTox)' |
| 6 | + required: true |
| 7 | + type: string |
| 8 | + cmake-args: |
| 9 | + description: 'Arguments to pass to CMake' |
| 10 | + required: false |
| 11 | + type: string |
| 12 | + screenshot: |
| 13 | + description: | |
| 14 | + Whether the smoke-test will output a screenshot. If true, the |
| 15 | + screenshot will be uploaded as an artifact. The smoke-test script |
| 16 | + must output the screenshot to the file named by the |
| 17 | + $QTOX_SCREENSHOT environment variable. |
| 18 | + required: false |
| 19 | + type: boolean |
| 20 | + smoke-test: |
| 21 | + description: 'Command to run to smoke test the AppImage' |
| 22 | + required: true |
| 23 | + type: string |
| 24 | + test-files: |
| 25 | + description: | |
| 26 | + List of test files needed to checkout from the repository. If your |
| 27 | + smoke-test script is local to the repository, it needs to be |
| 28 | + listed here. |
| 29 | + required: false |
| 30 | + type: string |
| 31 | + |
| 32 | +jobs: |
| 33 | + build: |
| 34 | + name: Build on Alpine |
| 35 | + strategy: |
| 36 | + matrix: |
| 37 | + arch: [x86_64] |
| 38 | + runs-on: ubuntu-24.04 |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@v4 |
| 41 | + with: |
| 42 | + fetch-depth: 0 |
| 43 | + - name: Fetch build scripts |
| 44 | + run: | |
| 45 | + git clone --depth=1 https://github.com/TokTok/dockerfiles "third_party/dockerfiles" |
| 46 | + cp third_party/dockerfiles/docker-compose.yml . |
| 47 | + - name: Determine artifact file name |
| 48 | + id: artifact |
| 49 | + run: | |
| 50 | + ARTIFACT="${{ inputs.project-name }}-$(git rev-parse --short HEAD | head -c7)-${{ matrix.arch }}.AppImage" |
| 51 | + echo "artifact=$ARTIFACT" >>$GITHUB_OUTPUT |
| 52 | + echo "artifact-ref=${{ inputs.project-name }}-${{ github.sha }}-appimage-${{ matrix.arch }}" >>$GITHUB_OUTPUT |
| 53 | + - name: Cache compiler output |
| 54 | + uses: actions/cache@v4 |
| 55 | + with: |
| 56 | + path: .cache/ccache |
| 57 | + key: ${{ github.job }}-appimage-ccache |
| 58 | + - name: Download Docker image |
| 59 | + run: docker compose run --rm alpine-appimage uname -a |
| 60 | + - name: Run build |
| 61 | + run: docker compose run |
| 62 | + --rm |
| 63 | + -e GITHUB_REPOSITORY="$GITHUB_REPOSITORY" |
| 64 | + -e GITHUB_REF="$GITHUB_REF" |
| 65 | + alpine-appimage |
| 66 | + platform/appimage/build.sh |
| 67 | + --arch ${{ matrix.arch }} |
| 68 | + --src-dir /qtox |
| 69 | + --project-name ${{ inputs.project-name }} |
| 70 | + -- |
| 71 | + ${{ inputs.cmake-args }} |
| 72 | + |
| 73 | + - name: Upload artifact |
| 74 | + uses: actions/upload-artifact@v4 |
| 75 | + with: |
| 76 | + name: ${{ steps.artifact.outputs.artifact-ref }} |
| 77 | + path: | |
| 78 | + ${{ steps.artifact.outputs.artifact }} |
| 79 | + ${{ steps.artifact.outputs.artifact }}.sha256 |
| 80 | + ${{ steps.artifact.outputs.artifact }}.zsync |
| 81 | + if-no-files-found: error |
| 82 | + - name: Get tag name for release file name |
| 83 | + if: contains(github.ref, 'refs/tags/v') |
| 84 | + id: get_version |
| 85 | + run: | |
| 86 | + VERSION="$(echo "$GITHUB_REF" | cut -d / -f 3)" |
| 87 | + echo "release_artifact=${{ inputs.project-name }}-$VERSION-${{ matrix.arch }}.AppImage" >>$GITHUB_OUTPUT |
| 88 | + - name: Rename artifact for release upload |
| 89 | + if: contains(github.ref, 'refs/tags/v') |
| 90 | + run: | |
| 91 | + cp "${{ steps.artifact.outputs.artifact }}" "${{ steps.get_version.outputs.release_artifact }}" |
| 92 | + cp "${{ steps.artifact.outputs.artifact }}.sha256" "${{ steps.get_version.outputs.release_artifact }}.sha256" |
| 93 | + cp "${{ steps.artifact.outputs.artifact }}.zsync" "${{ steps.get_version.outputs.release_artifact }}.zsync" |
| 94 | + - name: Upload to versioned release |
| 95 | + if: contains(github.ref, 'refs/tags/v') |
| 96 | + uses: ncipollo/release-action@v1 |
| 97 | + with: |
| 98 | + allowUpdates: true |
| 99 | + draft: true |
| 100 | + artifacts: "${{ steps.get_version.outputs.release_artifact }},${{ steps.get_version.outputs.release_artifact }}.sha256,${{ steps.get_version.outputs.release_artifact }}.zsync" |
| 101 | + - name: Rename artifact for nightly upload |
| 102 | + if: github.event_name == 'push' && github.ref == 'refs/heads/master' |
| 103 | + run: | |
| 104 | + cp "${{ steps.artifact.outputs.artifact }}" "${{ inputs.project-name }}-nightly-${{ matrix.arch }}.AppImage" |
| 105 | + cp "${{ steps.artifact.outputs.artifact }}.sha256" "${{ inputs.project-name }}-nightly-${{ matrix.arch }}.AppImage.sha256" |
| 106 | + cp "${{ steps.artifact.outputs.artifact }}.zsync" "${{ inputs.project-name }}-nightly-${{ matrix.arch }}.AppImage.zsync" |
| 107 | + - name: Upload to nightly release |
| 108 | + uses: ncipollo/release-action@v1 |
| 109 | + if: github.event_name == 'push' && github.ref == 'refs/heads/master' |
| 110 | + with: |
| 111 | + allowUpdates: true |
| 112 | + tag: nightly |
| 113 | + omitBodyDuringUpdate: true |
| 114 | + omitNameDuringUpdate: true |
| 115 | + prerelease: true |
| 116 | + replacesArtifacts: true |
| 117 | + artifacts: "${{ inputs.project-name }}-nightly-${{ matrix.arch }}.AppImage,${{ inputs.project-name }}-nightly-${{ matrix.arch }}.AppImage.sha256,${{ inputs.project-name }}-nightly-${{ matrix.arch }}.AppImage.zsync" |
| 118 | + |
| 119 | + test: |
| 120 | + name: Test on Ubuntu |
| 121 | + needs: [build] |
| 122 | + strategy: |
| 123 | + matrix: |
| 124 | + arch: [x86_64] |
| 125 | + runs-on: ubuntu-22.04 |
| 126 | + steps: |
| 127 | + - if: inputs.test-files |
| 128 | + uses: actions/checkout@v4 |
| 129 | + with: |
| 130 | + # Fetch tags if we're not already in a tag build. |
| 131 | + fetch-tags: ${{ !contains(github.ref, 'refs/tags/v') }} |
| 132 | + sparse-checkout: ${{ inputs.test-files }} |
| 133 | + - name: Determine artifact file name |
| 134 | + id: artifact |
| 135 | + run: | |
| 136 | + ARTIFACT="${{ inputs.project-name }}-$(git rev-parse --short HEAD | head -c7)-${{ matrix.arch }}.AppImage" |
| 137 | + echo "artifact=$ARTIFACT" >>$GITHUB_OUTPUT |
| 138 | + echo "artifact-ref=${{ inputs.project-name }}-${{ github.sha }}-appimage-${{ matrix.arch }}" >>$GITHUB_OUTPUT |
| 139 | + - name: Download artifact from build step |
| 140 | + uses: actions/download-artifact@v4 |
| 141 | + with: |
| 142 | + name: ${{ steps.artifact.outputs.artifact-ref }} |
| 143 | + - name: Run AppImage |
| 144 | + id: run |
| 145 | + run: | |
| 146 | + chmod +x ${{ steps.artifact.outputs.artifact }} |
| 147 | + ${{ inputs.smoke-test }} xvfb-run --auto-servernum ./${{ steps.artifact.outputs.artifact }} |
| 148 | + echo "screenshot=$QTOX_SCREENSHOT" >>$GITHUB_OUTPUT |
| 149 | + env: |
| 150 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 151 | + QTOX_SCREENSHOT: ${{ inputs.screenshot && format('{0}-AppImage-{1}.png', inputs.project-name, matrix.arch) }} |
| 152 | + - name: Upload screenshot artifact |
| 153 | + if: inputs.screenshot |
| 154 | + uses: actions/upload-artifact@v4 |
| 155 | + with: |
| 156 | + name: ${{ steps.run.outputs.screenshot }} |
| 157 | + path: ${{ steps.run.outputs.screenshot }} |
| 158 | + if-no-files-found: error |
| 159 | + - name: Upload screenshot to nightly release |
| 160 | + if: inputs.screenshot && github.event_name == 'push' && github.ref == 'refs/heads/master' |
| 161 | + uses: ncipollo/release-action@v1 |
| 162 | + with: |
| 163 | + allowUpdates: true |
| 164 | + tag: nightly |
| 165 | + omitBodyDuringUpdate: true |
| 166 | + omitNameDuringUpdate: true |
| 167 | + prerelease: true |
| 168 | + replacesArtifacts: true |
| 169 | + artifacts: ${{ steps.run.outputs.screenshot }} |
0 commit comments