Skip to content

Commit caca7ef

Browse files
committed
Use org variables for encrypted key/iv
1 parent f01a489 commit caca7ef

2 files changed

Lines changed: 10 additions & 53 deletions

File tree

github-action-build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ EOL
114114
# NB: Key and iv values were given as arguments.
115115
echo
116116
echo "== Decrypting GPG keypair =="
117-
openssl aes-256-cbc -K "$key" -iv "$iv" -in "$keyFile.enc" -out "$keyFile" -d
117+
openssl aes-256-cbc -pbkdf2 -K "$key" -iv "$iv" -in "$keyFile.enc" -out "$keyFile" -d
118118
checkSuccess $?
119119
fi
120120
if [ "$deployOK" -a -f "$keyFile" ]; then

github-actionify.sh

Lines changed: 9 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ gitactionSettingsFile=$gitactionDir/settings.xml
2020
gitactionNotifyScript=$gitactionDir/notify.sh
2121
credentialsDir=$HOME/.scijava/credentials
2222
varsFile=$credentialsDir/vars
23-
signingKeySourceFile=$credentialsDir/scijava-ci-signing.asc
23+
signingKeySourceFile=$credentialsDir/scijava-ci-signing.asc.enc
2424
signingKeyDestFile=$gitactionDir/signingkey.asc
2525
pomMinVersion='17.1.1'
2626
tmpFile=gitaction.tmp
@@ -141,10 +141,10 @@ EOL
141141
cat >"$tmpFile" <<EOL
142142
#!/bin/sh
143143
curl -fsLO https://raw.githubusercontent.com/scijava/scijava-scripts/master/github-action-build.sh
144-
sh github-action-build.sh
144+
sh github-action-build.sh \$signingKeySecret \$signingIvSecret
145145
EOL
146146
chmod +x "$tmpFile"
147-
update "$githactionBuildScript" "GitHub Action: add executable script $gitactionBuildScript" "true"
147+
update "$gitactionBuildScript" "GitHub Action: add executable script $gitactionBuildScript" "true"
148148

149149
# Remove obsolete GitHub-Actions-related files.
150150
if [ -f "$gitactionSettingsFile" ]
@@ -202,60 +202,17 @@ EOL
202202
update README.md 'GitHub Action: add badge to README.md'
203203
fi
204204

205-
# # encrypt key/value pairs in variables file
206-
# if [ -f "$varsFile" ]
207-
# then
208-
# while read p; do
209-
# # Skip comments. (Cannot use ${p:0:1} because it's bash-specific.)
210-
# case "$p" in
211-
# '#'*) continue;;
212-
# esac
213-
# info "Encrypting ${p%%=*}"
214-
# ######################### TODO #########################
215-
# yes | $EXEC travis encrypt --$mode "$p" --add env.global --repo "$repoSlug"
216-
# test $? -eq 0 || die "Failed to encrypt variable '$p'"
217-
# done <"$varsFile"
218-
# $EXEC git commit "$gitactionConfig" -m "GitHub Action: add encrypted environment variables"
219-
# else
220-
# warn "No $varsFile found. GitHub Action will not have any environment variables set!"
221-
# fi
222-
223-
# # add key/value pairs as env vars to yml file
224-
# if [ -f "$varsFile" ]
225-
# then
226-
# while read p; do
227-
# # Skip comments. (Cannot use ${p:0:1} because it's bash-specific.)
228-
# case "$p" in
229-
# '#'*) continue;;
230-
# esac
231-
# key=${p%%=*}
232-
# val=${p%%*=}
233-
# info "Encrypting ${key}"
234-
235-
# done <"$varsFile"
236-
# $EXEC git commit "$gitactionConfig" -m "GitHub Action: add encrypted environment variables"
237-
# else
238-
# warn "No $varsFile found. GitHub Action will not have any environment variables set!"
239-
# fi
240-
241-
# encrypt GPG keypair
205+
# copy the encrypted signing key
206+
# This assumes you have the encrypted signing key locally and will set the encryption key and iv as encrypted
207+
# environment variables in your repository or organization
242208
if [ -f "$signingKeySourceFile" ]
243209
then
244-
info "Encrypting $signingKeyDestFile"
210+
info "Copying $signingKeyDestFile"
245211
if [ -z "$EXEC" ]
246212
then
247213
rm -f "$signingKeyDestFile.enc"
248-
######################### TODO #########################
249-
# https://docs.github.com/en/github/authenticating-to-github/generating-a-new-gpg-key
250-
encryptOutput=$(travis encrypt-file --$mode "$signingKeySourceFile" "$signingKeyDestFile.enc" --repo "$repoSlug")
251-
test $? -eq 0 || die "Failed to encrypt signing key."
252-
encryptResult=$(echo "$encryptOutput" | grep openssl)
253-
test "$encryptResult" || die "No openssl variables emitted."
254-
key=$(echo "$encryptResult" | cut -d' ' -f4)
255-
iv=$(echo "$encryptResult" | cut -d' ' -f6)
256-
sed -i.bak "s/\(sh github-action-build.sh\)/\1 $key $iv/" "$gitactionBuildScript"
257-
rm -f "$gitactionBuildScript.bak"
258-
git add "$gitactionBuildScript" "$signingKeyDestFile.enc"
214+
cp "$signingKeySourceFile" "$signingKeyDestFile.enc"
215+
git add "$signingKeyDestFile.enc"
259216
git commit -m "GitHub Action: add encrypted GPG signing keypair"
260217
fi
261218
else

0 commit comments

Comments
 (0)