-
Notifications
You must be signed in to change notification settings - Fork 12
164 lines (150 loc) · 5.75 KB
/
create-tag-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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
name: Create tag release
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
- '[0-9]+.[0-9]+.[0-9]+-beta[0-9]+'
permissions:
actions: write
contents: write
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
jobs:
versioning:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.versioning.outputs.tag }}
version: ${{ steps.versioning.outputs.version }} # same as tag but without the -betaN part at the end, if present
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Necessary to fetch tags
- id: versioning
run: |
TAG=${GITHUB_REF#refs/tags/}
echo "Full version tag: $TAG"
TAG_COMMIT=$(git rev-list -n 1 $TAG)
MAIN_BRANCH_COMMIT=$(git rev-parse origin/${{ github.event.repository.default_branch }})
if ! git merge-base --is-ancestor $TAG_COMMIT $MAIN_BRANCH_COMMIT; then
echo "Tag is not on the main branch, stopping workflow."
exit 1
fi
if [[ $TAG =~ ^([0-9]+\.[0-9]+\.[0-9]+)(-beta[0-9]+)?$ ]]; then
echo "version=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
echo "tag=$TAG" >> $GITHUB_OUTPUT
else
echo "Error: Tag does not match the expected format 'X.Y.Z' or 'X.Y.Z-betaN'"
exit 1
fi
build-nuget:
needs: versioning
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
- run: dotnet restore NuGetOnly.slnf
- run: dotnet build NuGetOnly.slnf -c Release --no-restore
- run: dotnet test NuGetOnly.slnf -c Release --no-build --logger "trx;LogFileName=test_results.trx"
- run: dotnet pack NuGetOnly.slnf -c Release --no-build -o ./nupkg -p:Version=${{ needs.versioning.outputs.tag }}
- uses: actions/cache/save@v4
with:
path: nupkg
key: cache-${{ github.sha }}
build-vsix:
needs: versioning
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- run: | # Update VSIX version
[xml]$manifest = Get-Content "src\EcoCode.Vsix\source.extension.vsixmanifest"
$identity = $manifest.SelectSingleNode("//*[local-name()='Identity']")
if ($identity -ne $null) {
$identity.Version = "${{ needs.versioning.outputs.version }}"
}
$manifest.Save("src\EcoCode.Vsix\source.extension.vsixmanifest")
- uses: actions/setup-dotnet@v4
- run: dotnet restore VsixOnly.slnf
- uses: microsoft/setup-msbuild@v2
- run: msbuild VsixOnly.slnf "-p:OutputPath=..\..\vsix;Configuration=Release"
- uses: actions/cache/save@v4
with:
path: vsix
key: cache-${{ github.sha }}
enableCrossOsArchive: true
publish-nuget: # Only if both builds succeeded
needs: [versioning, build-nuget, build-vsix]
runs-on: ubuntu-latest
steps:
- uses: actions/cache/restore@v4
with:
path: nupkg
key: cache-${{ github.sha }}
fail-on-cache-miss: true
- run: echo "PACKAGE=$(find . -name "EcoCode.${{ needs.versioning.outputs.tag }}.nupkg" | head -n 1)" >> $GITHUB_ENV
- run: dotnet nuget push ${{ env.PACKAGE }} -k "${{ secrets.NUGET_API_KEY }}" -s https://api.nuget.org/v3/index.json
publish-vsix: # Only if both builds succeeded, and the tag is not a pre-release
needs: [versioning, build-nuget, build-vsix]
if: ${{ needs.versioning.outputs.tag == needs.versioning.outputs.version }}
runs-on: windows-latest
steps:
- uses: actions/cache/restore@v4
with:
path: vsix
key: cache-${{ github.sha }}
enableCrossOsArchive: true
fail-on-cache-miss: true
- uses: cezarypiatek/VsixPublisherAction@1.1
with:
extension-file: vsix\EcoCode.vsix
publish-manifest-file: vsix\publishManifest.json
personal-access-code: ${{ secrets.VSMARKETPLACE_API_KEY }}
create-release: # Only if both builds succeeded
needs: [versioning, build-nuget, build-vsix]
runs-on: ubuntu-latest
steps:
- uses: actions/cache/restore@v4
with:
path: nupkg
key: cache-${{ github.sha }}
fail-on-cache-miss: true
- uses: actions/cache/restore@v4
with:
path: vsix
key: cache-${{ github.sha }}
enableCrossOsArchive: true
fail-on-cache-miss: true
- uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.versioning.outputs.tag }}
name: ${{ needs.versioning.outputs.tag }}
draft: false
prerelease: ${{ needs.versioning.outputs.tag != needs.versioning.outputs.version }}
body: "Release of version ${{ needs.versioning.outputs.tag }}"
files: |
nupkg/**/EcoCode.${{ needs.versioning.outputs.tag }}.nupkg
vsix/EcoCode.vsix
# Adapt when the test project is hosted and ready
# update-test-project:
# needs: create-release
# runs-on: ubuntu-latest
# steps:
# - name: Checkout test project
# uses: actions/checkout@v4
# with:
# repository: 'your-github-username/ecoCode-csharp-test-project'
# token: ${{ secrets.TESTPROJECT_ACCESS_TOKEN }}
# path: 'test-project'
# - name: Update package version in csproj
# run: |
# sed -i 's/<PackageReference Include="EcoCode" Version=".*">/<PackageReference Include="EcoCode" Version="${{ needs.versioning.outputs.tag }}">' test-project/ecoCode-csharp-test-project.csproj
# - name: Commit and push if changed
# run: |
# cd test-project
# git config user.name github-actions
# git config user.email github-actions@github.com
# git add .
# git commit -m "Update EcoCode package version to ${{ needs.versioning.outputs.tag }}" || exit 0
# git push
# env:
# ACCESS_TOKEN: ${{ secrets.TESTPROJECT_ACCESS_TOKEN }}