-
Notifications
You must be signed in to change notification settings - Fork 3
213 lines (194 loc) · 7.17 KB
/
published_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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
name: published_release
on:
repository_dispatch:
types:
- imgpkg_released
- kapp_released
- kbld_released
- vendir_released
- ytt_released
- kctrl_released
- kwt_released
jobs:
process-release-information:
runs-on: ubuntu-latest
outputs:
yttValuesFile: ${{ steps.get-checksums-from-release.outputs.result }}
steps:
- uses: actions/github-script@v5
id: check-if-latest-release
with:
result-encoding: string
script: |
var crypto = require('crypto');
const owner = context.payload.client_payload.repo.split("/")[0]
const repo = context.payload.client_payload.repo.split("/")[1]
var latestRelease = await github.rest.repos.getLatestRelease({
owner,
repo,
});
tagName = latestRelease["data"].tag_name
if(tagName != context.payload.client_payload.tagName){
console.log("Going to cancel workflow because the tag used was not the latest release")
const cOwner = "${{ github.repository }}".split("/")[0]
const cRepo = "${{ github.repository }}".split("/")[1]
await github.rest.actions.cancelWorkflowRun({
owner: cOwner,
repo: cRepo,
run_id: ${{ github.run_id }},
});
return -1
}
return 0
- uses: actions/github-script@v5
id: get-checksums-from-release
if: startsWith(github.ref, 'refs/tags/') && ${{ !env.ACT }}
with:
result-encoding: string
script: |
var crypto = require('crypto');
const owner = context.payload.client_payload.repo.split("/")[0]
const repo = context.payload.client_payload.repo.split("/")[1]
// https://docs.github.com/en/rest/reference/repos#list-releases
// https://octokit.github.io/rest.js/v18#repos-list-releases
var releases = await github.rest.repos.listReleases({
owner: owner,
repo: repo
});
var crypto = require('crypto')
var fs = require('fs')
const url = require('url');
const https = require('https');
checksums = {}
for (const r of releases["data"]) {
console.log(`${r.tag_name} == ${ context.payload.client_payload.tagName }`)
if (!r.draft && r.tag_name == context.payload.client_payload.tagName) {
for (const asset of r.assets) {
var release_asset = await github.rest.repos.getReleaseAsset({ headers: {accept: `application/octet-stream`}, accept: `application/octet-stream`, owner: owner, repo: repo, asset_id: asset.id });
const hash = crypto.createHash('sha256');
let http_promise = new Promise((resolve, reject) => {
https.get(release_asset.url, (stream) => {
stream.on('data', function (data) {
hash.update(data);
});
stream.on('end', function () {
checksums[asset.name]= hash.digest('hex');
resolve(`${asset.name}`);
});
});
});
await http_promise;
}
break
}
}
console.log(checksums)
githubURL = `github.com/${context.payload.client_payload.repo}`
result = `
#@data/values
---
product: ${context.payload.client_payload.toolName}
version: ${context.payload.client_payload.tagName}
github:
url: ${githubURL}
assets:
`
for (const [key, value] of Object.entries(checksums)) {
if (key.indexOf(context.payload.client_payload.toolName) != -1) {
keyParts = key.split('.')[0].split("-")
result += `
- os: ${keyParts[1]}
arch: ${keyParts[2]}
shasum: ${value}
filename: ${key}
`
}
}
console.log(result)
return result
- name: Create release file
run: |
cat <<EOF >release.yml
${{ steps.get-checksums-from-release.outputs.result }}
EOF
- name: Upload Release information file
uses: actions/[email protected]
with:
name: ytt-data-values-for-release
path: ./release.yml
prepare-homebrew-file:
runs-on: ubuntu-latest
needs: process-release-information
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download ytt data values file with release information
uses: actions/[email protected]
with:
name: ytt-data-values-for-release
path: ./tmp/release.yml
- name: Install ytt
uses: carvel-dev/setup-action@v1
with:
only: ytt
- name: Generate Homebrew File
run: |
set -e -x
filename="./${{ github.event.client_payload.toolName }}.rb"
./scripts/generate_homebrew_formula.sh ./tmp/release.yml > $filename
cat $filename
- name: Upload Homebrew File
uses: actions/[email protected]
with:
name: homebrew-formula
path: ./${{ github.event.client_payload.toolName }}.rb
release-on-homebrew:
needs: prepare-homebrew-file
uses: carvel-dev/release-scripts/.github/workflows/commit-and-push.yml@main
secrets:
githubDeployPrivateKey: ${{ secrets.HOMEBREW_DEPLOY_PRIVATE_KEY }}
with:
repository: carvel-dev/homebrew
branch: develop
artifactName: homebrew-formula
artifactPath: .
prepare-releases-file-for-install-sh:
runs-on: ubuntu-latest
needs: process-release-information
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download ytt data values file with release information
uses: actions/[email protected]
with:
name: ytt-data-values-for-release
path: ./tmp/release.yml
- name: Install ytt
uses: carvel-dev/setup-action@v1
with:
only: ytt
token: ${{ secrets.GITHUB_TOKEN }}
- name: Generate new releases.yaml
run: |
set -e -x
./scripts/generate_releases_yaml.sh ./tmp/release.yml > ./tmp/releases.yaml
mv ./tmp/releases.yaml ./releases.yaml
- name: Upload releases.yaml File
uses: actions/[email protected]
with:
name: releases-yaml
path: releases.yaml
update-releases-yaml:
needs: prepare-releases-file-for-install-sh
uses: carvel-dev/release-scripts/.github/workflows/commit-and-push.yml@main
secrets:
githubDeployPrivateKey: ${{ secrets.CARVEL_RELEASE_SCRIPTS_DEPLOY_PRIVATE_KEY }}
with:
repository: carvel-dev/release-scripts
branch: main
artifactName: releases-yaml
artifactPath: .