This repository has been archived by the owner on Mar 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
191 lines (168 loc) · 7.63 KB
/
update-draft-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
name: Update Draft Release
"on":
push:
branches:
- main
jobs:
update:
name: Update Draft Release
runs-on:
- ubuntu-latest
steps:
- id: release-drafter
uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.RIFF_GITHUB_TOKEN }}
- name: Install yj
run: |
#!/usr/bin/env bash
set -euo pipefail
echo "Installing yj ${YJ_VERSION}"
mkdir -p "${HOME}"/bin
echo "${HOME}/bin" >> "${GITHUB_PATH}"
curl \
--location \
--show-error \
--silent \
--output "${HOME}"/bin/yj \
"https://github.com/sclevine/yj/releases/download/v${YJ_VERSION}/yj-linux"
chmod +x "${HOME}"/bin/yj
env:
YJ_VERSION: 5.0.0
- uses: actions/checkout@v2
- name: Update draft release with buildpack information
run: |
#!/usr/bin/env bash
set -euo pipefail
PAYLOAD="{}"
if [[ -e buildpack.toml ]]; then
PAYLOAD=$(jq -n -r \
--argjson PAYLOAD "${PAYLOAD}" \
--argjson BUILDPACK "$(yj -tj < buildpack.toml)" \
'$PAYLOAD | .primary = $BUILDPACK')
fi
if [[ -e builder.toml ]]; then
PAYLOAD=$(jq -n -r \
--argjson PAYLOAD "${PAYLOAD}" \
--argjson BUILDER "$(yj -tj < builder.toml)" \
'$PAYLOAD | .primary = $BUILDER')
for BUILDPACK in $(
jq -n -r \
--argjson PAYLOAD "${PAYLOAD}" \
'$PAYLOAD.primary.buildpacks[].uri | capture("(?:.+://)?(?<image>.+)") | .image'
); do
crane export "${BUILDPACK}" - | tar xf - --absolute-names --strip-components 1 --wildcards "/cnb/buildpacks/*/*/buildpack.toml"
done
fi
if [[ -e package.toml ]]; then
for PACKAGE in $(yj -t < package.toml | jq -r '.dependencies[].uri | capture("(?:.+://)?(?<image>.+)") | .image'); do
crane export "${PACKAGE}" - | tar xf - --absolute-names --strip-components 1 --wildcards "/cnb/buildpacks/*/*/buildpack.toml"
done
fi
if [[ -d buildpacks ]]; then
while IFS= read -r -d '' FILE; do
PAYLOAD=$(jq -n -r \
--argjson PAYLOAD "${PAYLOAD}" \
--argjson BUILDPACK "$(yj -tj < "${FILE}")" \
'$PAYLOAD | .buildpacks += [ $BUILDPACK ]')
done < <(find buildpacks -name buildpack.toml -print0)
fi
jq -n -r \
--argjson PAYLOAD "${PAYLOAD}" \
--arg RELEASE_NAME "${RELEASE_NAME}" \
'( select($PAYLOAD.primary.buildpack.name) | "\($PAYLOAD.primary.buildpack.name) \($RELEASE_NAME)" ) // "\($RELEASE_NAME)"' \
> "${HOME}"/name
jq -n -r \
--argjson PAYLOAD "${PAYLOAD}" \
--arg RELEASE_BODY "${RELEASE_BODY}" \
'
def id(b):
select(b.buildpack.id) | "**ID**: `\(b.buildpack.id)`"
;
def included_buildpackages(b): [
"#### Included Buildpackages:",
"Name | ID | Version",
":--- | :- | :------",
( b | sort_by(.buildpack.name | ascii_downcase) | map("\(.buildpack.name) | `\(.buildpack.id)` | `\(.buildpack.version)`") ),
""
];
def stacks(s): [
"#### Supported Stacks:",
( s | sort_by(.id | ascii_downcase) | map("- `\(.id)`") ),
""
];
def default_dependency_versions(d): [
"#### Default Dependency Versions:",
"ID | Version",
":- | :------",
( d | to_entries | sort_by(.key | ascii_downcase) | map("`\(.key)` | `\(.value)`") ),
""
];
def dependencies(d): [
"#### Dependencies:",
"Name | Version | SHA256",
":--- | :------ | :-----",
( d | sort_by(.name // .id | ascii_downcase) | map("\(.name // .id) | `\(.version)` | `\(.sha256)`")),
""
];
def order_groupings(o): [
"<details>",
"<summary>Order Groupings</summary>",
"",
( o | map([
"ID | Version | Optional",
":- | :------ | :-------",
( .group | map([ "`\(.id)` | ", (select(.version) | "`\(.version)`"), ( select(.optional) | "| `\(.optional)`" ) ] | join(" ")) ),
""
])),
"</details>",
""
];
def primary_buildpack(p): [
id(p.primary),
"**Digest**: <!-- DIGEST PLACEHOLDER -->",
"",
( select(p.buildpacks) | included_buildpackages(p.buildpacks) ),
( select(p.primary.stacks) | stacks(p.primary.stacks) ),
( select(p.primary.metadata."default-versions") | default_dependency_versions(p.primary.metadata."default-versions") ),
( select(p.primary.metadata.dependencies) | dependencies(p.primary.metadata.dependencies) ),
( select(p.primary.order) | order_groupings(p.primary.order) ),
( select(p.buildpacks) | "---" ),
""
];
def nested_buildpack(b): [
"<details>",
"<summary>\(b.buildpack.name) \(b.buildpack.version)</summary>",
"",
id(b),
"",
( select(b.stacks) | stacks(b.stacks) ),
( select(b.metadata."default-versions") | default_dependency_versions(b.metadata."default-versions") ),
( select(b.metadata.dependencies) | dependencies(b.metadata.dependencies) ),
( select(b.order) | order_groupings(b.order) ),
"---",
"",
"</details>",
""
];
$PAYLOAD | [
primary_buildpack(.),
( select(.buildpacks) | [ .buildpacks | sort_by(.buildpack.name | ascii_downcase) | map(nested_buildpack(.)) ] ),
"",
"---",
"",
$RELEASE_BODY
] | flatten | join("\n")
' > "${HOME}"/body
gh api \
--method PATCH \
"/repos/:owner/:repo/releases/${RELEASE_ID}" \
--field "tag_name=${RELEASE_TAG_NAME}" \
--field "name=@${HOME}/name" \
--field "body=@${HOME}/body"
env:
GITHUB_TOKEN: ${{ secrets.RIFF_GITHUB_TOKEN }}
RELEASE_BODY: ${{ steps.release-drafter.outputs.body }}
RELEASE_ID: ${{ steps.release-drafter.outputs.id }}
RELEASE_NAME: ${{ steps.release-drafter.outputs.name }}
RELEASE_TAG_NAME: ${{ steps.release-drafter.outputs.tag_name }}