Skip to content

Commit 77a35a4

Browse files
bradeglerverbanicm
authored andcommitted
feat: Added automation for generating checksums (#5)
Created a GitHub workflow that will run nightly to look for new Terraform release versions. If it finds new versions it will: * Generate a new terraform-checksums.json file * Submit a pull request for review
1 parent 8617134 commit 77a35a4

File tree

3 files changed

+69
-3
lines changed

3 files changed

+69
-3
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Default fallback
2-
* @sethvargo
2+
* @abcxyz/breakglass
33

44
# github-actions owns all files
55
* @abcxyz/github-actions

generate_version_checksums.sh renamed to .github/generate_version_checksums.sh

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/bin/sh
22

3-
mkdir temp
3+
mkdir -p temp
44
cd temp || exit
55

66
export GNUPGHOME=./.gnupg;
77

8-
checksum_file=../terraform-checksums.json
8+
checksum_file=../../terraform-checksums.json
99

1010
# Generate a temporary key to use for verification
1111
gpg --batch --quick-generate-key --batch --passphrase "" [email protected];
@@ -26,6 +26,11 @@ curl -s --remote-name ${release_url}/index.json;
2626
# Exclude all 0.x and pre-release versions
2727
jq -r 'select(.name=="terraform") | .versions[] | select(.version | (contains("-") or startswith("0.")) | not) | .version' < index.json > versions.list;
2828

29+
30+
added_file=added.list;
31+
32+
touch "${added_file}";
33+
2934
while IFS= read -r version;
3035
do
3136
exists=$(jq --arg version "${version}" '.versions[] | select(.version==$version)' < "${checksum_file}");
@@ -67,8 +72,25 @@ do
6772
mv updated.json "${checksum_file}";
6873

6974
done;
75+
76+
echo "${version}" >> "${added_file}";
7077
fi
7178

7279
done < versions.list;
7380

81+
# If there were any changes set some environment variables
82+
if [ -s ${added_file} ];
83+
then
84+
change_count=$(wc -l ${added_file} | tr -s ' ' | cut -d ' ' -f2);
85+
change_date=$(date +%Y-%m-%d);
86+
versions=$(cat ${added_file} | tr '\n' ',' | sed 's/,*$//g');
87+
88+
{
89+
echo "CHANGES=${change_count}";
90+
echo "PR_BRANCH=update-checksums-${change_date}";
91+
echo "UPDATE_DATE=${change_date}";
92+
echo "VERSIONS=${versions}";
93+
} >> "${GITHUB_ENV}";
94+
fi;
95+
7496
unset GNUPGHOME;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: 'Update Checksums File'
16+
on:
17+
workflow_dispatch:
18+
schedule:
19+
- cron: '0 0 */1 * *'
20+
21+
jobs:
22+
update-checksums:
23+
permissions:
24+
contents: 'write'
25+
packages: 'write'
26+
runs-on: 'ubuntu-latest'
27+
steps:
28+
- id: 'checkout'
29+
uses: 'actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8' # ratchet:actions/checkout@v3
30+
# Generate updates to the checksum file if there are new released versions of terraform
31+
- id: 'generate-updates'
32+
run: './.github/generate_version_checksums.sh;'
33+
# Create a pull request for review
34+
- id: 'create-pull-request'
35+
if: ${{ env.CHANGES }}
36+
uses: peter-evans/create-pull-request@b4d51739f96fca8047ad065eccef63442d8e99f7 # ratchet:peter-evans/create-pull-request@v4
37+
with:
38+
add-paths: 'terraform-checksums.json'
39+
commit-message: 'chore: [automated] checksum updates'
40+
delete-branch: true
41+
branch: '${{ env.PR_BRANCH }}'
42+
title: 'chore: Terraform checksum updates for ${{ env.UPDATE_DATE }}'
43+
body: |-
44+
Adds Terraform binary checksums for ${{ env.CHANGES }} versions: ${{ env.VERSIONS }}

0 commit comments

Comments
 (0)