Repository navigation
159 lines (134 loc) · 5.78 KB
/
Copy pathci.yml
File metadata and controls
159 lines (134 loc) · 5.78 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
151
152
153
154
155
156
157
158
159
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: CI
permissions:
contents: read
concurrency:
group: ci-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
on:
push:
branches:
- master
- release/*
paths-ignore:
- '**/*.md'
- '**/*.gitignore'
- '**/*.gitattributes'
pull_request:
branches:
- master
- release/*
paths-ignore:
- '**/*.md'
- '**/*.gitignore'
- '**/*.gitattributes'
jobs:
build:
if: github.event_name == 'pull_request' || (github.event_name == 'push' && contains(toJson(github.event.commits), '***NO_CI***') == false && contains(toJson(github.event.commits), '[ci skip]') == false && contains(toJson(github.event.commits), '[skip ci]') == false)
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
outputs:
publication_succeeded: ${{ steps.publish.outputs.succeeded }}
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true
DOTNET_GENERATE_ASPNET_CERTIFICATE: false
DOTNET_ADD_GLOBAL_TOOLS_TO_PATH: false
DOTNET_MULTILEVEL_LOOKUP: 0
steps:
- name: checkout code
uses: actions/checkout@v5
with:
persist-credentials: false
- name: setup .net core sdk
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x
9.0.x
10.0.x
- name: dotnet build
run: dotnet build solrevdev.seedfolder.sln --configuration Release
- name: run integration tests
run: ./tests/integration-test.sh
- name: dotnet pack
run: dotnet pack solrevdev.seedfolder.sln -c Release --no-build --include-source --include-symbols
- name: verify versioned package
id: package
shell: bash
run: |
version=$(sed -n 's:.*<Version>\(.*\)</Version>.*:\1:p' src/solrevdev.seedfolder.csproj)
package="src/nupkg/solrevdev.seedfolder.${version}.nupkg"
if [[ -z "$version" ]]; then
echo "Unable to find the package version." >&2
exit 1
fi
if [[ ! -f "$package" ]]; then
echo "Expected package does not exist: ${package}" >&2
exit 1
fi
echo "version=${version}" >> "$GITHUB_OUTPUT"
echo "package=${package}" >> "$GITHUB_OUTPUT"
- name: log in to NuGet
id: nuget
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: NuGet/login@v1
with:
user: solrevdev
- name: publish NuGet
id: publish
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
env:
NUGET_API_KEY: ${{ steps.nuget.outputs.NUGET_API_KEY }}
PACKAGE: ${{ steps.package.outputs.package }}
run: |
dotnet nuget push "$PACKAGE" \
--api-key "$NUGET_API_KEY" \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate
echo "succeeded=true" >> "$GITHUB_OUTPUT"
tag-release:
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/master' && needs.build.result == 'success' && needs.build.outputs.publication_succeeded == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: checkout published commit
uses: actions/checkout@v5
with:
ref: ${{ github.sha }}
- name: verify or create release tag
shell: bash
run: |
expected_commit="$GITHUB_SHA"
version=$(sed -n 's:.*<Version>\(.*\)</Version>.*:\1:p' src/solrevdev.seedfolder.csproj)
tag="v${version}"
if [[ -z "$version" ]]; then
echo "Unable to find the package version." >&2
exit 1
fi
if [[ "$(git rev-parse HEAD)" != "$expected_commit" ]]; then
echo "Checked-out commit does not match the intended release commit." >&2
exit 1
fi
if git ls-remote --exit-code --refs origin "refs/tags/${tag}" >/dev/null 2>&1; then
git fetch --no-tags origin "refs/tags/${tag}:refs/tags/${tag}"
tag_commit=$(git rev-list -n 1 "refs/tags/${tag}")
tag_version=$(git show "refs/tags/${tag}:src/solrevdev.seedfolder.csproj" | sed -n 's:.*<Version>\(.*\)</Version>.*:\1:p')
if [[ "$tag_commit" != "$expected_commit" ]]; then
echo "Tag ${tag} resolves to ${tag_commit}, expected ${expected_commit}." >&2
exit 1
fi
if [[ "$tag_version" != "$version" ]]; then
echo "Tag ${tag} contains version ${tag_version}, expected ${version}." >&2
exit 1
fi
echo "Tag ${tag} already identifies the published commit and version; safe retry."
exit 0
fi
git tag "$tag" "$expected_commit"
git push origin "refs/tags/${tag}:refs/tags/${tag}"