|
| 1 | +name: Release & Publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "**" |
| 7 | + |
| 8 | +jobs: |
| 9 | + release: |
| 10 | + name: Create release |
| 11 | + runs-on: ubuntu-latest |
| 12 | + outputs: |
| 13 | + tag: ${{ steps.release-tag.outputs.tag }} |
| 14 | + id: ${{ steps.release-id.outputs.id }} |
| 15 | + steps: |
| 16 | + - name: Determine tag |
| 17 | + id: release-tag |
| 18 | + run: | |
| 19 | + RELEASE_TAG=${GITHUB_REF#refs/tags/} |
| 20 | + echo "RELEASE_TAG=${RELEASE_TAG}" >> $GITHUB_ENV |
| 21 | + echo "tag=${RELEASE_TAG}" >> $GITHUB_OUTPUT |
| 22 | + - name: Create the release |
| 23 | + run: | |
| 24 | + curl \ |
| 25 | + -X POST \ |
| 26 | + -H "Accept: application/vnd.github+json" \ |
| 27 | + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 28 | + https://api.github.com/repos/${{ github.repository }}/releases \ |
| 29 | + --data '{ |
| 30 | + "tag_name": "${{ env.RELEASE_TAG }}", |
| 31 | + "name": "Release ${{ env.RELEASE_TAG }}", |
| 32 | + "generate_release_notes": true |
| 33 | + }' \ |
| 34 | + -o release.json |
| 35 | + - name: Determine release id |
| 36 | + id: release-id |
| 37 | + run: | |
| 38 | + RELEASE_ID=$(jq -r '.id' release.json) |
| 39 | + echo "id=${RELEASE_ID}" >> $GITHUB_OUTPUT |
| 40 | +
|
| 41 | + build-and-publish: |
| 42 | + name: Build and publish |
| 43 | + runs-on: ${{ matrix.job.os }} |
| 44 | + strategy: |
| 45 | + matrix: |
| 46 | + job: |
| 47 | + - os: ubuntu-latest |
| 48 | + target: x86_64-unknown-linux-gnu |
| 49 | + - os: macos-latest |
| 50 | + target: x86_64-apple-darwin |
| 51 | + - os: windows-latest |
| 52 | + target: x86_64-pc-windows-msvc |
| 53 | + needs: release |
| 54 | + steps: |
| 55 | + - name: Checkout code |
| 56 | + uses: actions/checkout@v3 |
| 57 | + - name: Build binary |
| 58 | + run: | |
| 59 | + rustup update stable |
| 60 | + rustup default stable |
| 61 | + rustup target add ${{ matrix.job.target }} |
| 62 | + cargo build --release --target ${{ matrix.job.target }} |
| 63 | + - name: Create tarball |
| 64 | + shell: bash |
| 65 | + run: | |
| 66 | + TARBALL=sws-${{ needs.release.outputs.tag }}-${{ matrix.job.target }}.tar.gz |
| 67 | + tar -zcvf ${TARBALL} -C target/${{ matrix.job.target }}/release sws |
| 68 | + echo "TARBALL=${TARBALL}" >> $GITHUB_ENV |
| 69 | + - name: Upload tarball to the release |
| 70 | + run: > |
| 71 | + curl \ |
| 72 | + -X POST |
| 73 | + -H "Accept: application/vnd.github+json" |
| 74 | + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" |
| 75 | + -H 'Content-Type: application/octet-stream' |
| 76 | + --upload-file ${{ env.TARBALL }} |
| 77 | + https://uploads.github.com/repos/${{ github.repository }}/releases/${{ needs.release.outputs.id }}/assets?name=${{ env.TARBALL }} |
0 commit comments