forked from BrianHenryIE/strauss
-
Notifications
You must be signed in to change notification settings - Fork 0
216 lines (190 loc) · 8.17 KB
/
Copy pathrelease.yml
File metadata and controls
216 lines (190 loc) · 8.17 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
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
214
215
216
name: Build, tag and attach releases
on:
release:
types: [published]
workflow_dispatch:
concurrency:
# Cancel previous runs of this workflow if they are testing the same branch
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
create-phar:
runs-on: ubuntu-latest
name: Create Strauss phar on new release
steps:
- name: Resolve release tag
id: resolve_release_tag
uses: actions/github-script@v9
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let tagName = context.payload.release?.tag_name;
if (!tagName) {
try {
const latestRelease = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo,
});
tagName = latestRelease.data.tag_name;
} catch (error) {
core.setFailed(`Unable to determine the latest published release tag: ${error.message}`);
return;
}
}
if (!tagName) {
core.setFailed('Unable to determine a release tag for this workflow run.');
return;
}
core.info(`Using release tag ${tagName}`);
core.setOutput('tag', tagName);
- name: Git checkout
uses: actions/checkout@v7
with:
ref: ${{ steps.resolve_release_tag.outputs.tag }}
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
tools: composer:v2
extensions: fileinfo, gd
- name: Install dependencies
run: composer install --no-dev --prefer-dist --no-progress
- name: "Edit `strauss/bin/strauss` to update the version number"
env:
CURRENT_RELEASE: ${{ steps.resolve_release_tag.outputs.tag }}
run: |
find bin -name 'strauss' -exec sed -i "s/}, '[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*');/}, '$CURRENT_RELEASE');/" {} +
- name: Commit updated README.md
uses: stefanzweifel/git-auto-commit-action@v7
with:
branch: master
file_pattern: "bin/strauss"
commit_message: "🤖 Update version number in bin"
- name: Create .phar
run: ./scripts/createphar.sh
- name: Test run strauss
run: php strauss.phar --version
- name: Check version
run: |
TAG_NAME="${{ steps.resolve_release_tag.outputs.tag }}"
CURRENT_VERSION="$(php strauss.phar --version | sed -e 's#^.\+ \([0-9.]\+\)$#\1#')"
if [ "${TAG_NAME#v}" != "${CURRENT_VERSION}" ]; then
echo "::error::Latest tag differs from current version"
exit 10
fi
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v7
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
# https://phar.io/howto/sign-and-upload-to-github.html
# https://keys.openpgp.org/about/usage/
# https://github.com/marketplace/actions/import-gpg
# gpg --armor --export-secret-key BrianHenryIE@gmail.com | pbcopy
# Specify exactly which key to export or it will export the first, expired key, and you will copy the wrong information to your secrets.
# gpg --armor --export-secret-key BE6D3AB4AD637A11A26983AD3915D8F4028A0673 | pbcopy
# TODO: command to pipe to gh CLI tool to set secret.
- name: Check GPG key validity
env:
GPG_USER: ${{ secrets.GPG_USER }}
run: |
KEY_INFO="$(gpg --batch --list-secret-keys --with-colons "$GPG_USER" 2>/dev/null || true)"
if [ -z "$KEY_INFO" ]; then
echo "::error title=GPG key not available::Unable to find an imported secret GPG key for '$GPG_USER'."
exit 1
fi
NOW="$(date +%s)"
PARSED_KEY_INFO="$(printf '%s\n' "$KEY_INFO" | awk -F: -v now="$NOW" '
$1=="sec" {
total++;
current_expiry=$7;
current_valid=(current_expiry=="" || current_expiry=="0" || current_expiry>now);
if (current_valid) {
valid_total++;
}
next;
}
$1=="fpr" {
if (current_valid && valid_fpr=="") {
valid_fpr=$10;
valid_expiry=current_expiry;
}
if (!current_valid && expired_fpr=="") {
expired_fpr=$10;
expired_expiry=current_expiry;
}
current_valid="";
current_expiry="";
}
END {
print "TOTAL_KEYS=" total+0;
print "VALID_KEYS=" valid_total+0;
print "KEY_FINGERPRINT=" valid_fpr;
print "KEY_EXPIRY=" valid_expiry;
print "EXPIRED_FINGERPRINT=" expired_fpr;
print "EXPIRED_EXPIRY=" expired_expiry;
}
')"
TOTAL_KEYS="0"
VALID_KEYS="0"
KEY_FINGERPRINT=""
KEY_EXPIRY=""
EXPIRED_FINGERPRINT=""
EXPIRED_EXPIRY=""
while IFS='=' read -r PARSED_KEY PARSED_VALUE; do
case "$PARSED_KEY" in
TOTAL_KEYS) TOTAL_KEYS="$PARSED_VALUE" ;;
VALID_KEYS) VALID_KEYS="$PARSED_VALUE" ;;
KEY_FINGERPRINT) KEY_FINGERPRINT="$PARSED_VALUE" ;;
KEY_EXPIRY) KEY_EXPIRY="$PARSED_VALUE" ;;
EXPIRED_FINGERPRINT) EXPIRED_FINGERPRINT="$PARSED_VALUE" ;;
EXPIRED_EXPIRY) EXPIRED_EXPIRY="$PARSED_VALUE" ;;
esac
done <<< "$PARSED_KEY_INFO"
if [ "$TOTAL_KEYS" -eq 0 ]; then
echo "::error title=GPG key not available::Unable to find an imported secret GPG key for '$GPG_USER'."
exit 1
fi
if [ -z "$KEY_FINGERPRINT" ]; then
if [ -n "$EXPIRED_EXPIRY" ] && [ "$EXPIRED_EXPIRY" != "0" ]; then
EXPIRES_AT="$(date -u -d "@$EXPIRED_EXPIRY" '+%Y-%m-%d %H:%M:%S UTC')"
echo "::error title=GPG key expired::Found $TOTAL_KEYS matching key(s) for '$GPG_USER', but all are expired (for example: $EXPIRED_FINGERPRINT expired on $EXPIRES_AT)."
else
echo "::error title=Unable to inspect imported GPG key::Found $TOTAL_KEYS matching key(s) for '$GPG_USER', but none could be validated for signing."
fi
echo "Rotate the signing key, update GPG_PRIVATE_KEY / GPG_USER / PASSPHRASE secrets, and rerun this workflow."
echo "PHAR signing guide: https://phar.io/howto/sign-and-upload-to-github.html"
echo "OpenPGP key publishing guide: https://keys.openpgp.org/about/usage/"
exit 1
fi
if [ -n "$KEY_EXPIRY" ] && [ "$KEY_EXPIRY" != "0" ]; then
if [ "$KEY_EXPIRY" -le "$NOW" ]; then
EXPIRES_AT="$(date -u -d "@$KEY_EXPIRY" '+%Y-%m-%d %H:%M:%S UTC')"
echo "::error title=GPG key expired::The imported GPG signing key $KEY_FINGERPRINT expired on $EXPIRES_AT."
echo "Rotate the signing key, update GPG_PRIVATE_KEY / GPG_USER / PASSPHRASE secrets, and rerun this workflow."
echo "PHAR signing guide: https://phar.io/howto/sign-and-upload-to-github.html"
echo "OpenPGP key publishing guide: https://keys.openpgp.org/about/usage/"
exit 1
fi
fi
echo "SIGNING_KEY_FINGERPRINT=$KEY_FINGERPRINT" >> "$GITHUB_ENV"
echo "Imported $TOTAL_KEYS matching key(s); using non-expired key $KEY_FINGERPRINT for signing."
- name: Sign the PHAR
run: |
ls strauss.phar
gpg --local-user ${{ secrets.GPG_USER }} \
--batch \
--yes \
--passphrase="${{ secrets.PASSPHRASE }}" \
--detach-sign \
--output strauss.phar.asc \
strauss.phar
- uses: meeDamian/github-release@2.0
with:
tag: ${{ steps.resolve_release_tag.outputs.tag }}
token: ${{ secrets.GITHUB_TOKEN }}
files: |
strauss.phar
strauss.phar.asc
gzip: false
allow_override: true