-
Notifications
You must be signed in to change notification settings - Fork 0
150 lines (130 loc) · 4.19 KB
/
release-cli.yml
File metadata and controls
150 lines (130 loc) · 4.19 KB
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
name: Release CLI
on:
workflow_dispatch:
jobs:
validate:
name: Validate version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.read_version.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Read version from semver.txt
id: read_version
run: |
version=$(tr -d '[:space:]' < src/CoderPatros.Tea.Cli/semver.txt)
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: Validate semver format
run: |
if ! echo "${{ steps.read_version.outputs.version }}" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?(\+[a-zA-Z0-9.]+)?$'; then
echo "::error::Version '${{ steps.read_version.outputs.version }}' is not valid semver"
exit 1
fi
- name: Check tag does not exist
run: |
if git ls-remote --tags https://github.com/${{ github.repository }} | grep -q "refs/tags/cli/v${{ steps.read_version.outputs.version }}$"; then
echo "::error::Tag cli/v${{ steps.read_version.outputs.version }} already exists"
exit 1
fi
test:
name: Test (${{ matrix.os }})
needs: validate
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
build:
name: Build (${{ matrix.rid }})
needs: [validate, test]
runs-on: ${{ matrix.runner }}
env:
VERSION: ${{ needs.validate.outputs.version }}
strategy:
fail-fast: false
matrix:
include:
- rid: linux-x64
runner: ubuntu-latest
archive: tar.gz
- rid: linux-arm64
runner: ubuntu-latest
archive: tar.gz
- rid: osx-x64
runner: macos-latest
archive: tar.gz
- rid: osx-arm64
runner: macos-latest
archive: tar.gz
- rid: win-x64
runner: windows-latest
archive: zip
- rid: win-arm64
runner: windows-latest
archive: zip
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Publish
run: >
dotnet publish src/CoderPatros.Tea.Cli/CoderPatros.Tea.Cli.csproj
-c Release
-r ${{ matrix.rid }}
--self-contained true
-p:PublishSingleFile=true
-p:DebugType=none
-p:Version=${{ env.VERSION }}
-o ./publish
- name: Archive (tar.gz)
if: matrix.archive == 'tar.gz'
run: tar -czf tea-cli-v${{ env.VERSION }}-${{ matrix.rid }}.tar.gz -C ./publish .
- name: Archive (zip)
if: matrix.archive == 'zip'
shell: pwsh
run: Compress-Archive -Path ./publish/* -DestinationPath tea-cli-v${{ env.VERSION }}-${{ matrix.rid }}.zip
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: tea-cli-v${{ env.VERSION }}-${{ matrix.rid }}
path: tea-cli-v${{ env.VERSION }}-${{ matrix.rid }}.${{ matrix.archive }}
release:
name: Release
needs: [validate, build]
runs-on: ubuntu-latest
permissions:
contents: write
env:
VERSION: ${{ needs.validate.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
merge-multiple: true
- name: Create and push tag
run: |
git tag "cli/v${{ env.VERSION }}"
git push origin "cli/v${{ env.VERSION }}"
- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
tag_name: cli/v${{ env.VERSION }}
name: CLI v${{ env.VERSION }}
generate_release_notes: true
files: ./artifacts/*