Skip to content

Automatic release on tag creation #188

Automatic release on tag creation

Automatic release on tag creation #188

#This aumtomaticly release when a pul request to main is accepted
name: Automatic release on tag creation
permissions: write-all
on:
push:
tags:
- 'v*.*.*'
workflow_run:
workflows: ['Create tag on PR Merge']
types: [completed]
workflow_dispatch:
jobs:
build-and-release:
runs-on: ubuntu-latest
if: ${{ github.event_name != 'workflow_run' || (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') }}
steps:
# Checkout the code
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 #Fetch all history and tags
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.x'
- name: Restore dependencies
run: dotnet restore Chirp/
- name: Build
run: dotnet build --no-restore Chirp/
- name: Install playwright
working-directory: Chirp/test/PlaywrightTests/bin/Debug/net8.0/
run: pwsh playwright.ps1 install --with-deps
- name: Test
working-directory: Chirp/
env:
authentication_github_clientId: ${{ secrets.GITHUBCLIENTID }}
authentication_github_clientSecret: ${{ secrets.GITHUBCLIENTSECRET }}
run: dotnet test --verbosity normal
# Get the latest tag from the repository
- name: Get latest tag
run: |
LATEST_TAG=$(git describe --tags --abbrev=0 || echo "v0.0.0") # Get latest tag or default to v0.0.0
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
echo "Current latest tag is $LATEST_TAG"
- name: release for all platforms
working-directory: Chirp/src/Chirp.Web/
run: |
dotnet publish --runtime linux-x64 -p:PublishSingleFile=true --self-contained true
dotnet publish --runtime win-x64 -p:PublishSingleFile=true --self-contained true
dotnet publish --runtime osx-x64 -p:PublishSingleFile=true --self-contained true
# Create ZIP files
- name: Zip the output
working-directory: Chirp/src/Chirp.Web/bin/Release/net8.0/
run: |
zip -r chirp-${{ env.LATEST_TAG }}-linux-x64.zip linux-x64/publish/Chirp.Web
zip -r chirp-${{ env.LATEST_TAG }}-win-x64.zip win-x64/publish/Chirp.Web.exe
zip -r chirp-${{ env.LATEST_TAG }}-osx-x64.zip osx-x64/publish/Chirp.Web
# Upload the release artifacts and create the release
- name: Create GitHub release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.LATEST_TAG }}
name: Release ${{ env.LATEST_TAG }} # Set release name
files: |
Chirp/src/Chirp.Web/bin/Release/net8.0/chirp-${{ env.LATEST_TAG }}-linux-x64.zip
Chirp/src/Chirp.Web/bin/Release/net8.0/chirp-${{ env.LATEST_TAG }}-win-x64.zip
Chirp/src/Chirp.Web/bin/Release/net8.0/chirp-${{ env.LATEST_TAG }}-osx-x64.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}