From 18d3d72cc29b276a06dba21087b6023b6bbfc918 Mon Sep 17 00:00:00 2001 From: Nara Kasbergen Kwon <855115+xiehan@users.noreply.github.com> Date: Thu, 30 Nov 2023 14:56:39 +0100 Subject: [PATCH] chore: use 'feat' for minor version provider upgrades (#361) Use 'fix' for patch version provider upgrades, for proper semantic versioning and consistency. --- src/provider-upgrade.ts | 25 ++++++++++--- test/__snapshots__/index.test.ts.snap | 51 +++++++++++++++++++++++---- 2 files changed, 66 insertions(+), 10 deletions(-) diff --git a/src/provider-upgrade.ts b/src/provider-upgrade.ts index 0a038cf5..aa21b602 100644 --- a/src/provider-upgrade.ts +++ b/src/provider-upgrade.ts @@ -36,6 +36,7 @@ export class ProviderUpgrade { "${{ steps.check_version.outputs.new_version == 'available' }}"; const currentVersion = "${{ steps.current_version.outputs.value }}"; const newVersion = "${{ steps.new_version.outputs.value }}"; + const semanticType = "${{ steps.release.outputs.type }}"; workflow.addJobs({ upgrade: { @@ -46,7 +47,7 @@ export class ProviderUpgrade { steps: [ { name: "Checkout", - uses: "actions/checkout@v2", + uses: "actions/checkout@v4", }, { run: "yarn install" }, { @@ -73,19 +74,35 @@ export class ProviderUpgrade { 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 1 <<< "$CURRENT_VERSION")`, + `NEW_VERSION_MINOR=$(cut -d "." -f 1 <<< "$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: { - "commit-message": `fix: upgrade provider from \`${currentVersion}\` to version \`${newVersion}\``, branch: "auto/provider-upgrade", - title: `fix: upgrade provider from \`${currentVersion}\` to version \`${newVersion}\``, + "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", token: "${{ secrets.GH_TOKEN }}", diff --git a/test/__snapshots__/index.test.ts.snap b/test/__snapshots__/index.test.ts.snap index 560835d3..3d911d15 100644 --- a/test/__snapshots__/index.test.ts.snap +++ b/test/__snapshots__/index.test.ts.snap @@ -595,6 +595,19 @@ jobs: id: new_version if: \${{ steps.check_version.outputs.new_version == 'available' }} run: echo "value=$(jq -r '. | to_entries[] | .value' src/version.json)" >> $GITHUB_OUTPUT + - name: Determine if this is a minor or patch release + id: release + if: \${{ steps.check_version.outputs.new_version == 'available' }} + env: + CURRENT_VERSION: \${{ steps.current_version.outputs.value }} + NEW_VERSION: \${{ steps.new_version.outputs.value }} + run: |- + CURRENT_VERSION_MINOR=$(cut -d "." -f 1 <<< "$CURRENT_VERSION") + NEW_VERSION_MINOR=$(cut -d "." -f 1 <<< "$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 - if: \${{ steps.check_version.outputs.new_version == 'available' }} run: yarn compile - if: \${{ steps.check_version.outputs.new_version == 'available' }} @@ -603,9 +616,9 @@ jobs: if: \${{ steps.check_version.outputs.new_version == 'available' }} uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38 with: - commit-message: "fix: upgrade provider from \`\${{ steps.current_version.outputs.value }}\` to version \`\${{ steps.new_version.outputs.value }}\`" branch: auto/provider-upgrade - title: "fix: upgrade provider from \`\${{ steps.current_version.outputs.value }}\` to version \`\${{ steps.new_version.outputs.value }}\`" + commit-message: "\${{ steps.release.outputs.type }}: upgrade provider from \`\${{ steps.current_version.outputs.value }}\` to version \`\${{ steps.new_version.outputs.value }}\`" + title: "\${{ steps.release.outputs.type }}: upgrade provider from \`\${{ steps.current_version.outputs.value }}\` to version \`\${{ steps.new_version.outputs.value }}\`" body: This PR upgrades the underlying Terraform provider to version \${{ steps.new_version.outputs.value }} labels: automerge token: \${{ secrets.GH_TOKEN }} @@ -3281,6 +3294,19 @@ jobs: id: new_version if: \${{ steps.check_version.outputs.new_version == 'available' }} run: echo "value=$(jq -r '. | to_entries[] | .value' src/version.json)" >> $GITHUB_OUTPUT + - name: Determine if this is a minor or patch release + id: release + if: \${{ steps.check_version.outputs.new_version == 'available' }} + env: + CURRENT_VERSION: \${{ steps.current_version.outputs.value }} + NEW_VERSION: \${{ steps.new_version.outputs.value }} + run: |- + CURRENT_VERSION_MINOR=$(cut -d "." -f 1 <<< "$CURRENT_VERSION") + NEW_VERSION_MINOR=$(cut -d "." -f 1 <<< "$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 - if: \${{ steps.check_version.outputs.new_version == 'available' }} run: yarn compile - if: \${{ steps.check_version.outputs.new_version == 'available' }} @@ -3289,9 +3315,9 @@ jobs: if: \${{ steps.check_version.outputs.new_version == 'available' }} uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38 with: - commit-message: "fix: upgrade provider from \`\${{ steps.current_version.outputs.value }}\` to version \`\${{ steps.new_version.outputs.value }}\`" branch: auto/provider-upgrade - title: "fix: upgrade provider from \`\${{ steps.current_version.outputs.value }}\` to version \`\${{ steps.new_version.outputs.value }}\`" + commit-message: "\${{ steps.release.outputs.type }}: upgrade provider from \`\${{ steps.current_version.outputs.value }}\` to version \`\${{ steps.new_version.outputs.value }}\`" + title: "\${{ steps.release.outputs.type }}: upgrade provider from \`\${{ steps.current_version.outputs.value }}\` to version \`\${{ steps.new_version.outputs.value }}\`" body: This PR upgrades the underlying Terraform provider to version \${{ steps.new_version.outputs.value }} labels: automerge token: \${{ secrets.GH_TOKEN }} @@ -5958,6 +5984,19 @@ jobs: id: new_version if: \${{ steps.check_version.outputs.new_version == 'available' }} run: echo "value=$(jq -r '. | to_entries[] | .value' src/version.json)" >> $GITHUB_OUTPUT + - name: Determine if this is a minor or patch release + id: release + if: \${{ steps.check_version.outputs.new_version == 'available' }} + env: + CURRENT_VERSION: \${{ steps.current_version.outputs.value }} + NEW_VERSION: \${{ steps.new_version.outputs.value }} + run: |- + CURRENT_VERSION_MINOR=$(cut -d "." -f 1 <<< "$CURRENT_VERSION") + NEW_VERSION_MINOR=$(cut -d "." -f 1 <<< "$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 - if: \${{ steps.check_version.outputs.new_version == 'available' }} run: yarn compile - if: \${{ steps.check_version.outputs.new_version == 'available' }} @@ -5966,9 +6005,9 @@ jobs: if: \${{ steps.check_version.outputs.new_version == 'available' }} uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38 with: - commit-message: "fix: upgrade provider from \`\${{ steps.current_version.outputs.value }}\` to version \`\${{ steps.new_version.outputs.value }}\`" branch: auto/provider-upgrade - title: "fix: upgrade provider from \`\${{ steps.current_version.outputs.value }}\` to version \`\${{ steps.new_version.outputs.value }}\`" + commit-message: "\${{ steps.release.outputs.type }}: upgrade provider from \`\${{ steps.current_version.outputs.value }}\` to version \`\${{ steps.new_version.outputs.value }}\`" + title: "\${{ steps.release.outputs.type }}: upgrade provider from \`\${{ steps.current_version.outputs.value }}\` to version \`\${{ steps.new_version.outputs.value }}\`" body: This PR upgrades the underlying Terraform provider to version \${{ steps.new_version.outputs.value }} labels: automerge token: \${{ secrets.GH_TOKEN }}