Skip to content

Commit

Permalink
Make the version strategy similar to passwordless-server
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Nov 1, 2023
1 parent d4890a1 commit 2b6c889
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,26 @@ env:
# steps to more sensitive access scopes.

jobs:
# Determine version
version:
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Determine stable version
id: stable-version
if: ${{ github.event_name == 'release' }}
run: echo "version=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT

- name: Determine prerelease version
id: pre-version
if: ${{ github.event_name != 'release' }}
run: echo "version=0.0.0-ci-${{ github.event.pull_request.head.sha || github.sha }}" >> $GITHUB_OUTPUT

outputs:
version: ${{ steps.stable-version.outputs.version || steps.pre-version.outputs.version }}

# Check formatting
format:
runs-on: ubuntu-latest
Expand All @@ -62,7 +82,6 @@ jobs:

strategy:
fail-fast: false
max-parallel: 3
matrix:
os: [ubuntu-latest, windows-latest]

Expand Down Expand Up @@ -95,6 +114,7 @@ jobs:
# Pack the output into NuGet packages
pack:
needs: version
runs-on: ubuntu-latest
permissions:
actions: write
Expand All @@ -117,29 +137,14 @@ jobs:
--configuration Release
-p:ContinuousIntegrationBuild=true
# When triggered by `push` or `pull_request` events, generate a prerelease version
# for the packages, so as to clearly indicate that it's not a stable version release.
- name: Generate prerelease version
id: prerelease-version
if: ${{ github.event_name != 'release' }}
run: |
time=$(date +%s)
ref="${{ github.head_ref || github.ref_name }}"
ref_clean=$ref
ref_clean="${ref_clean/\//-}"
ref_clean="${ref_clean/_/-}"
echo "version=0.0.0-ci-$time-$ref_clean" >> $GITHUB_OUTPUT
- name: Create packages
run: >
dotnet pack
-p:Version=${{ needs.version.outputs.version }}
-p:ContinuousIntegrationBuild=true
--no-restore
--no-build
--configuration Release
-p:ContinuousIntegrationBuild=true
${{ steps.prerelease-version.outputs.version && format('-p:Version={0}', steps.prerelease-version.outputs.version) || '' }}
- name: Upload artifacts
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
Expand Down Expand Up @@ -189,7 +194,10 @@ jobs:
# Notify the Slack channel about the release
notify:
if: ${{ github.event_name == 'release' }}
needs: deploy
needs:
- version
- deploy

runs-on: ubuntu-latest

steps:
Expand All @@ -202,5 +210,5 @@ jobs:
Content-Type: application/json; charset=UTF-8
body: |
{
"text": "*Passwordless-dotnet* version `${{ github.event.release.name }}` has been released! 🎉\nDetails: ${{ github.event.release.html_url }}"
"text": "*Passwordless-dotnet* version `${{ needs.version.outputs.version }}` has been released! 🎉\nDetails: ${{ github.event.release.html_url }}"
}

0 comments on commit 2b6c889

Please sign in to comment.