|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + pull_request: |
| 6 | + branches: |
| 7 | + - 'master' |
| 8 | + |
| 9 | +jobs: |
| 10 | + prepare: |
| 11 | + name: Prepare |
| 12 | + runs-on: ubuntu-latest |
| 13 | + outputs: |
| 14 | + trusted: ${{ steps.contains_tag.outputs.retval }} |
| 15 | + matrix_json: ${{ steps.crystal_action.outputs.matrix_json }} |
| 16 | + crystal_version: ${{ steps.crystal_action.outputs.crystal_version }} |
| 17 | + steps: |
| 18 | + - name: Checkout |
| 19 | + uses: actions/checkout@v3 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Lint |
| 24 | + uses: crystal-ameba/[email protected] |
| 25 | + env: |
| 26 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 27 | + |
| 28 | + - name: Determine if tag is on trusted branch |
| 29 | + uses: rickstaa/action-contains-tag@0f592a0dd54a67d9af4545f6b6687ee01853d9a7 |
| 30 | + id: contains_tag |
| 31 | + with: |
| 32 | + frail: false |
| 33 | + reference: "master" |
| 34 | + tag: "${{ github.ref }}" |
| 35 | + |
| 36 | + - name: Crystal Action |
| 37 | + id: crystal_action |
| 38 | + run: .github/workflows/crystal_action.rb |
| 39 | + |
| 40 | + build: |
| 41 | + name: Test & Build |
| 42 | + needs: prepare |
| 43 | + strategy: |
| 44 | + fail-fast: true |
| 45 | + matrix: |
| 46 | + include: ${{ fromJson(needs.prepare.outputs.matrix_json) }} |
| 47 | + runs-on: ${{ matrix.platform }} |
| 48 | + permissions: |
| 49 | + contents: write |
| 50 | + |
| 51 | + steps: |
| 52 | + - name: Checkout |
| 53 | + uses: actions/checkout@v3 |
| 54 | + |
| 55 | + - if: matrix.platform != 'ubuntu-latest' && !endsWith(matrix.platform, '-arm') |
| 56 | + name: Install Crystal |
| 57 | + uses: crystal-lang/install-crystal@v1 |
| 58 | + with: |
| 59 | + crystal: ${{ matrix.crystal }} |
| 60 | + |
| 61 | + - if: matrix.platform != 'ubuntu-latest' && !endsWith(matrix.platform, '-arm') |
| 62 | + name: Test & Build (on runner host) |
| 63 | + run: | |
| 64 | + make clean ci release |
| 65 | +
|
| 66 | + - if: matrix.platform == 'ubuntu-latest' || endsWith(matrix.platform, '-arm') |
| 67 | + name: Test & Build (in alpine) |
| 68 | + uses: addnab/docker-run-action@v3 |
| 69 | + with: |
| 70 | + image: 84codes/crystal:${{ matrix.crystal }}-alpine |
| 71 | + options: -v ${{ github.workspace }}:/workspace |
| 72 | + run: | |
| 73 | + cd /workspace && make clean ci release |
| 74 | +
|
| 75 | + - if: startsWith(github.ref, 'refs/tags/') && matrix.crystal == needs.prepare.outputs.crystal_version && needs.prepare.outputs.trusted == 'true' |
| 76 | + name: Compute checksum |
| 77 | + run: | |
| 78 | + shasum -a 256 build/* >checksums.txt |
| 79 | +
|
| 80 | + - if: startsWith(github.ref, 'refs/tags/') && matrix.crystal == needs.prepare.outputs.crystal_version && needs.prepare.outputs.trusted == 'true' |
| 81 | + name: Upload artifacts |
| 82 | + uses: actions/upload-artifact@v3 |
| 83 | + with: |
| 84 | + name: sha256-${{ matrix.platform }} |
| 85 | + path: checksums.txt |
| 86 | + |
| 87 | + - if: startsWith(github.ref, 'refs/tags/') && matrix.crystal == needs.prepare.outputs.crystal_version && needs.prepare.outputs.trusted == 'true' |
| 88 | + name: Draft release |
| 89 | + uses: ncipollo/release-action@v1 |
| 90 | + with: |
| 91 | + artifacts: "build/*" |
| 92 | + allowUpdates: true |
| 93 | + draft: true |
| 94 | + updateOnlyUnreleased: false |
| 95 | + generateReleaseNotes: false |
| 96 | + omitBody: true |
| 97 | + |
| 98 | + release: |
| 99 | + name: Release |
| 100 | + needs: [prepare, build] |
| 101 | + permissions: |
| 102 | + contents: write |
| 103 | + runs-on: ubuntu-latest |
| 104 | + |
| 105 | + if: startsWith(github.ref, 'refs/tags/') && needs.prepare.outputs.trusted == 'true' |
| 106 | + steps: |
| 107 | + - name: Checkout |
| 108 | + uses: actions/checkout@v3 |
| 109 | + |
| 110 | + - name: Download artifacts |
| 111 | + uses: actions/download-artifact@v3 |
| 112 | + |
| 113 | + - name: Generate Release Notes |
| 114 | + run: .github/workflows/release_notes.sh >release.txt |
| 115 | + |
| 116 | + - name: Finish Release |
| 117 | + uses: ncipollo/release-action@v1 |
| 118 | + with: |
| 119 | + allowUpdates: true |
| 120 | + draft: false |
| 121 | + updateOnlyUnreleased: false |
| 122 | + generateReleaseNotes: false |
| 123 | + bodyFile: release.txt |
| 124 | + omitBody: false |
| 125 | + |
0 commit comments