-
Notifications
You must be signed in to change notification settings - Fork 0
117 lines (96 loc) · 3.84 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# 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
- 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"
git push
fi
- name: Move tag
run: |
# 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 }}
- name: Get commit hash
id: get_commit_hash
shell: bash
run: |
echo "commit-hash=$(git rev-parse HEAD)"
echo "commit-hash=$(git rev-parse HEAD)" >> "$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
}