Update: make ci happy #3
Workflow file for this run
This file contains 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
name: Release | |
on: | |
push: | |
tags: | |
- 'v*' | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Rust | |
uses: ATiltedTree/setup-rust@v1 | |
with: | |
rust-version: stable | |
- name: Build application | |
run: cargo build --profile dist | |
- name: Compress artifacts | |
run: | | |
if [ ${{ matrix.os }} == "windows-latest" ]; then | |
tar -czf target/dsp-calculator-${{ matrix.os }}.tar.gz target/debug/dsp-calculator.exe | |
else | |
tar -czf target/dsp-calculator-${{ matrix.os }}.tar.gz target/debug/dsp-calculator | |
fi | |
- name: Archive artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.os }}-release | |
path: target/dsp-calculator-${{ matrix.os }}.tar.gz | |
publish: | |
needs: build | |
runs-on: ubuntu-latest | |
if: startsWith(github.ref, 'refs/tags/v') | |
steps: | |
- name: Download artifacts | |
uses: actions/download-artifact@v2 | |
with: | |
path: release | |
- name: Determine if pre-release | |
id: prerelease_check | |
run: | | |
MAJOR_VERSION=$(echo "${{ github.ref }}" | sed -E 's/^refs\/tags\/v([0-9]+)\..*$/\1/') | |
if [[ $MAJOR_VERSION == "0" ]]; then | |
echo "Pre-release" | |
echo "::set-output name=is_prerelease::true" | |
else | |
echo "Not a pre-release" | |
echo "::set-output name=is_prerelease::false" | |
fi | |
- name: Create Release | |
id: create_release | |
run: | | |
gh release create ${{ github.ref }} \ | |
--title "Release ${{ github.ref }}" \ | |
--generate-notes \ | |
--prerelease ${{ steps.prerelease_check.outputs.is_prerelease }} | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Upload Release Asset | |
id: upload-release-asset | |
run: | | |
gh release upload ${{ github.ref }} release/* --clobber | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
cleanup: | |
runs-on: ubuntu-latest | |
needs: [publish] | |
steps: | |
- name: Clean up artifacts | |
uses: actions/github-script@v4 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const artifacts = await github.actions.listArtifactsForRepo({ | |
per_page: 100 | |
}); | |
const artifactIds = artifacts.data.artifacts | |
.filter(artifact => artifact.name !== 'release') | |
.map(artifact => artifact.id); | |
for (const id of artifactIds) { | |
await github.actions.deleteArtifact({ | |
artifact_id: id | |
}); | |
} |