Skip to content

Commit

Permalink
Feat: Add GitHub Actions workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
HuangFuSL committed Mar 20, 2024
1 parent 4f1d114 commit ba68779
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
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: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-release
path: target/release/dsp-calculator*

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
});
}

0 comments on commit ba68779

Please sign in to comment.