Skip to content

Commit

Permalink
auto version update improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
VJftw committed Jan 22, 2024
1 parent 0e73a04 commit ce95407
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
20 changes: 8 additions & 12 deletions .github/workflows/update_versions.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Update Versions PR

on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch: {}

permissions:
Expand All @@ -12,24 +14,18 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Fetch versions
- name: Mirror versions
id: mirror-versions
run: |-
bazel run //scripts:mirror_terraform_releases > terraform/private/versions_new.bzl
- name: Commit and push update
run: |-
mv terraform/private/versions_new.bzl terraform/private/versions.bzl
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
git checkout -b update-terraform-versions
git add terraform/private/versions.bzl
git commit -m "Updated Terraform Versions"
git push origin -u update-terraform-versions
bazel run //scripts:mirror_terraform_releases
- name: Create PR
if: steps.mirror-versions.outputs.has_changes
run: >-
gh pr create --base main --title 'Update Terraform Versions' --body 'Created by Github action'
gh pr create --base main --fill
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24 changes: 23 additions & 1 deletion scripts/mirror_terraform_releases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# replace the `./terraform/private/versions.bzl` file.
set -Eeuo pipefail

VERSIONS_FILE="$(git rev-parse --show-toplevel)/terraform/private/versions.bzl"

# https://www.hashicorp.com/.well-known/pgp-key.txt
hashicorp_pgp_key_file="$1"

Expand Down Expand Up @@ -68,11 +70,31 @@ for terraform_release_url in "${terraform_release_url_dirs[@]}"; do

done

cat <<EOF
cat <<EOF > "$VERSIONS_FILE"
"""
GENERATED by \`bazel run //scripts/mirror_terraform_releases\`
Mirror of Terraform Release info.
"""
TERRAFORM_VERSIONS = $json
EOF

>&2 echo "Wrote $VERSIONS_FILE"


if [ -z "$(git status --porcelain "$VERSIONS_FILE")" ]; then
>&2 echo "No new version information generated, exiting"
exit 0
fi

date="$(date --utc -I)"

>&2 echo "New version information generated, committing"
git checkout -b "auto-update-versions-$date"
git add "$VERSIONS_FILE"
git commit -m "Auto updated Terraform versions $date"
git push origin -u "auto-update-versions-$date"

if [ -n "${GITHUB_OUTPUT:-}" ]; then
echo "has_changes=true" >> "$GITHUB_OUTPUT"
fi

0 comments on commit ce95407

Please sign in to comment.