v1.0.0-beta.1 #24
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
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json | |
name: release | |
on: | |
workflow_dispatch: # Allow running the workflow manually from the GitHub UI | |
release: | |
types: | |
- published # Run the workflow when a new GitHub release is published | |
permissions: | |
contents: write | |
env: | |
# Source: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables#dotnet_skip_first_time_experience | |
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 | |
# Source: https://learn.microsoft.com/en-us/dotnet/core/tools/telemetry#disclosure | |
DOTNET_NOLOGO: true | |
NUGET_DIR: ${{ github.workspace }}/nuget | |
defaults: | |
run: | |
shell: pwsh | |
jobs: | |
update_version: | |
runs-on: ubuntu-latest | |
outputs: | |
commit-hash: ${{ steps.get_commit_hash.outputs.commit-hash }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: main | |
fetch-tags: true | |
- name: Update version | |
shell: bash | |
run: | | |
# Extract version from GitHub context | |
VERSION=$(echo "${{ github.event.release.tag_name }}" | sed 's/^v//') | |
# Find all .csproj files that contain a <Version> tag and update them | |
find . -name '*.csproj' -print0 | xargs -0 grep -l '<Version>' | xargs -I {} sed -i 's|<Version>.*</Version>|<Version>'$VERSION'</Version>|' {} | |
# Check for changes | |
if ! git diff --quiet; then | |
# Print out the diffs for the changes | |
git diff | |
# Commit changes | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git commit -am "chore: 🔧 updated version to $VERSION" | |
CURRENT_TAG_HASH=$(git rev-list -n 1 ${{ github.event.release.tag_name }}) | |
echo "Moving tag '${{ github.event.release.tag_name }}' to commit '$(git rev-parse HEAD)' from commit '${CURRENT_TAG_HASH}'" | |
# Delete the old tag locally | |
git tag -d ${{ github.event.release.tag_name }} | |
# Delete the old tag from the remote repository | |
git push origin :${{ github.event.release.tag_name }} | |
# Create a new tag at the current commit | |
git tag ${{ github.event.release.tag_name }} | |
# Push the new tag to the remote repository | |
git push origin ${{ github.event.release.tag_name }} | |
# Push all changes | |
git push | |
else | |
echo "Version as expected. Skipping version update commit." | |
fi | |
- name: Get commit hash | |
id: get_commit_hash | |
shell: bash | |
run: | | |
echo "commit-hash=$(git rev-list -n 1)" | |
echo "commit-hash=$(git rev-list -n 1)" >> "$GITHUB_OUTPUT" | |
# Can't pass env variables to reusable workflow, so we use this hack | |
workflow_environment_vars: | |
runs-on: ubuntu-latest | |
outputs: | |
nuget_dir: ${{ env.NUGET_DIR }} | |
steps: | |
- run: | | |
echo "nuget_dir: ${{ env.NUGET_DIR }}" | |
create_and_validate_nuget: | |
needs: [ workflow_environment_vars, update_version ] | |
uses: ./.github/workflows/package.yml | |
with: | |
nuget-dir: ${{ needs.workflow_environment_vars.outputs.nuget_dir }} | |
commit-hash: ${{ needs.update_version.outputs.commit-hash }} | |
test: | |
uses: ./.github/workflows/test.yml | |
deploy: | |
runs-on: ubuntu-latest | |
needs: [ create_and_validate_nuget, test ] | |
steps: | |
# Download the NuGet package created in the previous job | |
- uses: actions/download-artifact@v3 | |
with: | |
name: nuget | |
path: ${{ env.NUGET_DIR }} | |
# Install the .NET SDK indicated in the global.json file | |
- name: Setup .NET Core | |
uses: actions/setup-dotnet@v3 | |
# Publish all NuGet packages to NuGet.org | |
# Use --skip-duplicate to prevent errors if a package with the same version already exists. | |
# If you retry a failed workflow, already published packages will be skipped without error. | |
- name: Publish NuGet package | |
run: | | |
foreach($file in (Get-ChildItem "${{ env.NUGET_DIR }}" -Recurse -Include *.nupkg)) { | |
dotnet nuget push $file --api-key "${{ secrets.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate | |
} |