generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 1
182 lines (151 loc) · 5.82 KB
/
pack-and-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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
name: Publish
on:
workflow_call:
inputs:
prerelease:
type: boolean
jobs:
parse:
runs-on: ubuntu-22.04
outputs:
package: ${{ steps.parse-package.outputs.result }}
steps:
- name: Parse Package
id: parse-package
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
result-encoding: string
script: |
const ref = '${{ github.ref }}';
if (!ref.startsWith('refs/heads/')) {
core.setFailed(`Unexpected ref: ${ref}`);
return;
}
// Example: refs/heads/release/{packageName}/{version}
// 0 /1 /2 /3 /4
const refParts = ref.split('/');
if (refParts.length < 4) {
core.setFailed(`Not at least 4 parts split by forward slash: ${ref}`);
return;
}
return refParts[3];
pack:
name: Pack
runs-on: ubuntu-22.04
needs:
- parse
outputs:
current-version: ${{ steps.current-version.outputs.VERSION }}
steps:
- name: Check out repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up .NET
uses: actions/setup-dotnet@3e891b0cb619bf60e2c25674b222b8940e2c1c25 # v4.1.0
- name: Pack
run: dotnet pack -c Release -p:IsPreRelease=$IS_PRERELEASE
working-directory: '${{ needs.parse.outputs.package }}/src'
env:
IS_PRERELEASE: ${{ inputs.prerelease }}
- name: Get current version
id: current-version
run: echo "VERSION=$(dotnet msbuild -p:IsPreRelease=$IS_PRERELEASE --getProperty:Version)" >> $GITHUB_OUTPUT
working-directory: '${{ needs.parse.outputs.package }}/src'
env:
IS_PRERELEASE: ${{ inputs.prerelease }}
- name: Upload artifacts
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: packages
path: "**/*.nupkg"
publish:
name: Publish
runs-on: ubuntu-22.04
needs:
- pack
steps:
- name: Dispatch publishing
env:
GITHUB_TOKEN: ${{ secrets.PUBLISH_GITHUB_TOKEN }}
# TODO: Make version optional in workflow
run: >
gh workflow run publish-nuget.yml
--repo bitwarden/devops
--field repository=${{ github.event.repository.name }}
--field run-id=${{ github.run_id }}
--field artifact=packages
--field environment=nuget
--field version=1.0.0
create-release:
name: Create release
runs-on: ubuntu-22.04
needs:
- parse
- pack
- publish
steps:
- name: Create GitHub Release
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const package = '${{ inputs.package }}';
const currentVersion = '${{ needs.pack.outputs.current-version }}';
// Configure Git
await exec.exec(`git config user.name "github-actions"`);
await exec.exec(`git config user.email "[email protected]"`);
// List existing tags so that we could use them to link to the best full changelog
// Debug purposes only right now until there is enough data for me to make this command bullet proof
await exec.exec(`git --no-pager tag --list "${package}_v*" --no-contains $(git rev-parse HEAD)`, [], {
listeners: {
stdout: function stdout(data) {
console.log(`Found tags:\n${data}`);
}
}
});
// Create tag
const tag = `${package}_v${currentVersion}`;
console.log(`Creating tag & release: ${tag}`);
await exec.exec(`git tag "${tag}"`);
await exec.exec(`git push origin --tags`);
// Create release
const { data } = await github.rest.repos.createRelease({
owner: "bitwarden",
repo: "dotnet-extensions",
tag_name: tag,
target_commitish: "${{ github.event.ref }}",
name: tag,
body: "",
prerelease: ${{ inputs.prerelease }},
generate_release_notes: false, // This creates a link between this and the last tag but that might not be our version
});
const templateMarker = data.upload_url.indexOf("{");
let url = data.upload_url;
if (templateMarker > -1) {
url = url.substring(0, templateMarker);
}
const globber = await glob.create("**/*.nupkg");
const files = await globber.glob();
const fs = require("fs");
const path = require("path");
if (files.length === 0) {
core.setFailed("No files found, cannot create release.");
return;
}
for (const file of files) {
const endpoint = new URL(url);
endpoint.searchParams.append("name", path.basename(file));
const endpointString = endpoint.toString();
console.log(`Uploading file: ${file} to ${endpointString}`);
// do the upload
const uploadResponse = await github.request({
method: "POST",
url: endpointString,
data: fs.readFileSync(file),
});
console.log(`Upload response: ${uploadResponse.status}`);
}
console.log("Finished creating release.");
- name: Do version bump
uses: bitwarden/dotnet-extensions/.github/workflows/version-bump.yml@main
with:
package: ${{ needs.parse.outputs.package }}
type: ${{ inputs.prerelease && 'prerelease' || 'ga' }}