-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ci): setup Terraform on ubuntu-latest (#452)
Addresses the `terraform` CLI being removed from new GitHub Actions runner images, which is preventing automated provider upgrades to happen for all of our providers that don't use custom runners.
- Loading branch information
Showing
3 changed files
with
105 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
*/ | ||
|
||
import { javascript } from "projen"; | ||
import { JobPermission } from "projen/lib/github/workflows-model"; | ||
import { JobPermission, JobStep } from "projen/lib/github/workflows-model"; | ||
import { generateRandomCron } from "./util/random-cron"; | ||
|
||
interface ProviderUpgradeOptions { | ||
|
@@ -47,88 +47,103 @@ export class ProviderUpgrade { | |
const newVersion = "${{ steps.new_version.outputs.value }}"; | ||
const semanticType = "${{ steps.release.outputs.type }}"; | ||
|
||
const steps: JobStep[] = [ | ||
{ | ||
name: "Checkout", | ||
uses: "actions/checkout@v4", | ||
}, | ||
{ | ||
name: "Setup Node.js", | ||
uses: "actions/setup-node", | ||
with: { | ||
"node-version": project.minNodeVersion, | ||
}, | ||
}, | ||
{ run: "yarn install" }, | ||
{ | ||
id: "check_version", | ||
run: "yarn check-if-new-provider-version", | ||
}, | ||
{ | ||
name: "get provider current version", | ||
if: newerVersionAvailable, | ||
id: "current_version", | ||
run: `echo "value=$(jq -r '.cdktf.provider.version' package.json)" >> $GITHUB_OUTPUT`, | ||
}, | ||
{ | ||
run: "yarn fetch", | ||
if: newerVersionAvailable, | ||
env: { | ||
CHECKPOINT_DISABLE: "1", | ||
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}", | ||
}, | ||
}, | ||
{ | ||
name: "get provider updated version", | ||
if: newerVersionAvailable, | ||
id: "new_version", | ||
run: `echo "value=$(jq -r '. | to_entries[] | .value' src/version.json)" >> $GITHUB_OUTPUT`, | ||
}, | ||
{ | ||
name: "Determine if this is a minor or patch release", | ||
if: newerVersionAvailable, | ||
id: "release", | ||
env: { | ||
CURRENT_VERSION: currentVersion, | ||
NEW_VERSION: newVersion, | ||
}, | ||
run: [ | ||
`CURRENT_VERSION_MINOR=$(cut -d "." -f 2 <<< "$CURRENT_VERSION")`, | ||
`NEW_VERSION_MINOR=$(cut -d "." -f 2 <<< "$NEW_VERSION")`, | ||
`[[ "$CURRENT_VERSION_MINOR" != "$NEW_VERSION_MINOR" ]] && IS_MINOR_RELEASE=true || IS_MINOR_RELEASE=false`, | ||
`[[ "$IS_MINOR_RELEASE" == "true" ]] && SEMANTIC_TYPE=feat || SEMANTIC_TYPE=fix`, | ||
`echo "is_minor=$IS_MINOR_RELEASE" >> $GITHUB_OUTPUT`, | ||
`echo "type=$SEMANTIC_TYPE" >> $GITHUB_OUTPUT`, | ||
].join("\n"), | ||
}, | ||
// generate docs | ||
{ run: "yarn compile", if: newerVersionAvailable }, | ||
{ run: "yarn docgen", if: newerVersionAvailable }, | ||
// submit a PR | ||
{ | ||
name: "Create Pull Request", | ||
if: newerVersionAvailable, | ||
uses: "peter-evans/create-pull-request@v3", | ||
with: { | ||
branch: "auto/provider-upgrade", | ||
"commit-message": `${semanticType}: upgrade provider from \`${currentVersion}\` to version \`${newVersion}\``, | ||
title: `${semanticType}: upgrade provider from \`${currentVersion}\` to version \`${newVersion}\``, | ||
body: `This PR upgrades the underlying Terraform provider to version ${newVersion}`, | ||
labels: "automerge,auto-approve", | ||
token: "${{ secrets.GH_TOKEN }}", | ||
"delete-branch": true, | ||
committer: "team-tf-cdk <[email protected]>", | ||
author: "Team Terraform CDK <[email protected]>", | ||
signoff: true, | ||
}, | ||
}, | ||
]; | ||
|
||
// @TODO Figure out if this is really necessary; this has not been tested | ||
// But I saw https://github.com/hashicorp/setup-terraform/issues/425 | ||
// so I added this "if" statement as a precaution | ||
if (options.workflowRunsOn.includes("ubuntu-latest")) { | ||
steps.splice(2, 0, { | ||
name: "Setup Terraform", | ||
uses: "hashicorp/setup-terraform", | ||
with: { | ||
terraform_wrapper: false, | ||
}, | ||
}); | ||
} | ||
|
||
workflow.addJobs({ | ||
upgrade: { | ||
runsOn: options.workflowRunsOn, | ||
env: { | ||
NODE_OPTIONS: `--max-old-space-size=${options.nodeHeapSize}`, | ||
}, | ||
steps: [ | ||
{ | ||
name: "Checkout", | ||
uses: "actions/checkout@v4", | ||
}, | ||
{ | ||
name: "Setup Node.js", | ||
uses: "actions/setup-node", | ||
with: { | ||
"node-version": project.minNodeVersion, | ||
}, | ||
}, | ||
{ run: "yarn install" }, | ||
{ | ||
id: "check_version", | ||
run: "yarn check-if-new-provider-version", | ||
}, | ||
{ | ||
name: "get provider current version", | ||
if: newerVersionAvailable, | ||
id: "current_version", | ||
run: `echo "value=$(jq -r '.cdktf.provider.version' package.json)" >> $GITHUB_OUTPUT`, | ||
}, | ||
{ | ||
run: "yarn fetch", | ||
if: newerVersionAvailable, | ||
env: { | ||
CHECKPOINT_DISABLE: "1", | ||
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}", | ||
}, | ||
}, | ||
{ | ||
name: "get provider updated version", | ||
if: newerVersionAvailable, | ||
id: "new_version", | ||
run: `echo "value=$(jq -r '. | to_entries[] | .value' src/version.json)" >> $GITHUB_OUTPUT`, | ||
}, | ||
{ | ||
name: "Determine if this is a minor or patch release", | ||
if: newerVersionAvailable, | ||
id: "release", | ||
env: { | ||
CURRENT_VERSION: currentVersion, | ||
NEW_VERSION: newVersion, | ||
}, | ||
run: [ | ||
`CURRENT_VERSION_MINOR=$(cut -d "." -f 2 <<< "$CURRENT_VERSION")`, | ||
`NEW_VERSION_MINOR=$(cut -d "." -f 2 <<< "$NEW_VERSION")`, | ||
`[[ "$CURRENT_VERSION_MINOR" != "$NEW_VERSION_MINOR" ]] && IS_MINOR_RELEASE=true || IS_MINOR_RELEASE=false`, | ||
`[[ "$IS_MINOR_RELEASE" == "true" ]] && SEMANTIC_TYPE=feat || SEMANTIC_TYPE=fix`, | ||
`echo "is_minor=$IS_MINOR_RELEASE" >> $GITHUB_OUTPUT`, | ||
`echo "type=$SEMANTIC_TYPE" >> $GITHUB_OUTPUT`, | ||
].join("\n"), | ||
}, | ||
// generate docs | ||
{ run: "yarn compile", if: newerVersionAvailable }, | ||
{ run: "yarn docgen", if: newerVersionAvailable }, | ||
// submit a PR | ||
{ | ||
name: "Create Pull Request", | ||
if: newerVersionAvailable, | ||
uses: "peter-evans/create-pull-request@v3", | ||
with: { | ||
branch: "auto/provider-upgrade", | ||
"commit-message": `${semanticType}: upgrade provider from \`${currentVersion}\` to version \`${newVersion}\``, | ||
title: `${semanticType}: upgrade provider from \`${currentVersion}\` to version \`${newVersion}\``, | ||
body: `This PR upgrades the underlying Terraform provider to version ${newVersion}`, | ||
labels: "automerge,auto-approve", | ||
token: "${{ secrets.GH_TOKEN }}", | ||
"delete-branch": true, | ||
committer: "team-tf-cdk <[email protected]>", | ||
author: "Team Terraform CDK <[email protected]>", | ||
signoff: true, | ||
}, | ||
}, | ||
], | ||
steps, | ||
permissions: { | ||
pullRequests: JobPermission.WRITE, | ||
issues: JobPermission.WRITE, | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.