chore: add release workflow
This commit is contained in:
92
.github/workflows/build-and-release.yml
vendored
Normal file
92
.github/workflows/build-and-release.yml
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
name: Build and Release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
create_release:
|
||||
description: 'Create a GitHub release'
|
||||
required: false
|
||||
default: false
|
||||
type: boolean
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
version: ${{ steps.nbgv.outputs.SemVer2 }}
|
||||
should_release: ${{ steps.check-release.outputs.should_release }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # Required for GitVersioning
|
||||
|
||||
- name: Setup .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
dotnet-version: 9.0.x
|
||||
|
||||
- name: Install nbgv tool
|
||||
run: dotnet tool install -g nbgv
|
||||
|
||||
- name: Get version
|
||||
id: nbgv
|
||||
run: |
|
||||
VERSION=$(nbgv get-version --format json | jq -r '.SemVer2')
|
||||
echo "SemVer2=$VERSION" >> $GITHUB_OUTPUT
|
||||
echo "Version: $VERSION"
|
||||
|
||||
- name: Check if this is a release
|
||||
id: check-release
|
||||
run: |
|
||||
# Check if tag already exists
|
||||
if git rev-parse "v${{ steps.nbgv.outputs.SemVer2 }}" >/dev/null 2>&1; then
|
||||
echo "Tag v${{ steps.nbgv.outputs.SemVer2 }} already exists"
|
||||
echo "should_release=false" >> $GITHUB_OUTPUT
|
||||
else
|
||||
# Release if manually triggered or if this is a non-prerelease version on main
|
||||
if [[ "${{ github.event.inputs.create_release }}" == "true" ]] || [[ "${{ github.ref }}" == "refs/heads/main" && "${{ steps.nbgv.outputs.SemVer2 }}" != *"-"* ]]; then
|
||||
echo "should_release=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "should_release=false" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
fi
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore
|
||||
|
||||
- name: Build
|
||||
run: dotnet build --configuration Release --no-restore
|
||||
|
||||
- name: Publish executables
|
||||
if: steps.check-release.outputs.should_release == 'true'
|
||||
run: |
|
||||
dotnet publish src/GithubRepoRemover/GithubRepoRemover.csproj -c Release -r win-x64 -p:PublishSingleFile=true -o dist/win-x64
|
||||
dotnet publish src/GithubRepoRemover/GithubRepoRemover.csproj -c Release -r osx-x64 -p:PublishSingleFile=true -o dist/osx-x64
|
||||
dotnet publish src/GithubRepoRemover/GithubRepoRemover.csproj -c Release -r osx-arm64 -p:PublishSingleFile=true -o dist/osx-arm64
|
||||
dotnet publish src/GithubRepoRemover/GithubRepoRemover.csproj -c Release -r linux-x64 -p:PublishSingleFile=true -o dist/linux-x64
|
||||
|
||||
- name: Rename executables
|
||||
if: steps.check-release.outputs.should_release == 'true'
|
||||
run: |
|
||||
mv dist/win-x64/GithubRepoRemover.exe dist/github-repo-remover-win-x64.exe
|
||||
mv dist/osx-x64/GithubRepoRemover dist/github-repo-remover-osx-x64
|
||||
mv dist/osx-arm64/GithubRepoRemover dist/github-repo-remover-osx-arm64
|
||||
mv dist/linux-x64/GithubRepoRemover dist/github-repo-remover-linux-x64
|
||||
|
||||
- name: Create GitHub Release
|
||||
if: steps.check-release.outputs.should_release == 'true'
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
tag_name: v${{ steps.nbgv.outputs.SemVer2 }}
|
||||
name: Release v${{ steps.nbgv.outputs.SemVer2 }}
|
||||
generate_release_notes: true
|
||||
files: |
|
||||
dist/github-repo-remover-win-x64.exe
|
||||
dist/github-repo-remover-osx-x64
|
||||
dist/github-repo-remover-osx-arm64
|
||||
dist/github-repo-remover-linux-x64
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
Reference in New Issue
Block a user