Skip to content

Bump Terraform Provider Version #13

Bump Terraform Provider Version

Bump Terraform Provider Version #13

name: Bump Terraform Provider Version
on:
workflow_dispatch:
inputs:
terraform_version:
description: 'Terraform Provider Version (e.g., v0.24.5)'
required: true
type: string
branch:
description: 'Branch name (optional, if not provided will create release-cp-vX.Y.Z)'
required: false
type: string
env:
BRANCH_PREFIX: "release-cp-"
jobs:
bump-terraform-provider:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Validate input version format and set branch
run: |
if [[ ! "${{ github.event.inputs.terraform_version }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Version must be in format vX.Y.Z (e.g., v0.24.5)"
exit 1
fi
# Set VERSION with 'v' prefix
VERSION="${{ github.event.inputs.terraform_version }}"
echo "VERSION=$VERSION" >> $GITHUB_ENV
# Remove 'v' prefix for version number
VERSION_NUMBER="${VERSION#v}"
echo "VERSION_NUMBER=$VERSION_NUMBER" >> $GITHUB_ENV
echo "Version number (without v): $VERSION_NUMBER"
# Set branch name based on input
if [[ -n "${{ github.event.inputs.branch }}" ]]; then
echo "BRANCH_NAME=${{ github.event.inputs.branch }}" >> $GITHUB_ENV
echo "USE_EXISTING_BRANCH=true" >> $GITHUB_ENV
echo "Using provided branch: ${{ github.event.inputs.branch }}"
else
echo "BRANCH_NAME=${BRANCH_PREFIX}${{ github.event.inputs.terraform_version }}" >> $GITHUB_ENV
echo "USE_EXISTING_BRANCH=false" >> $GITHUB_ENV
echo "Will create new branch: ${BRANCH_PREFIX}${{ github.event.inputs.terraform_version }}"
fi
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Create and checkout new branch
if: env.USE_EXISTING_BRANCH == 'false'
run: |
git checkout -b "${{ env.BRANCH_NAME }}"
echo "Created and switched to branch: ${{ env.BRANCH_NAME }}"
- name: Checkout existing branch
if: env.USE_EXISTING_BRANCH == 'true'
run: |
git fetch origin "${{ env.BRANCH_NAME }}"
git checkout "${{ env.BRANCH_NAME }}"
echo "Checked out existing branch: ${{ env.BRANCH_NAME }}"
- name: Update Terraform Provider Version in Makefile
run: |
# Find and update the TERRAFORM_PROVIDER_VERSION line (remove 'v' prefix)
sed -i "s/^export TERRAFORM_PROVIDER_VERSION := .*/export TERRAFORM_PROVIDER_VERSION := ${{ env.VERSION_NUMBER }}/" Makefile
# Verify the change
echo "Updated TERRAFORM_PROVIDER_VERSION line:"
grep "export TERRAFORM_PROVIDER_VERSION" Makefile
# Check if the change was applied
if grep -q "export TERRAFORM_PROVIDER_VERSION := ${{ env.VERSION_NUMBER }}" Makefile; then
echo "✅ Successfully updated TERRAFORM_PROVIDER_VERSION to ${{ env.VERSION_NUMBER }}"
else
echo "❌ Failed to update TERRAFORM_PROVIDER_VERSION"
exit 1
fi
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true
- name: Install goimports
run: go install golang.org/x/tools/cmd/goimports@latest
- name: Verify provider version exists
run: |
echo "Checking if spectrocloud provider version ${{ env.VERSION }} exists..."
VERSION_URL="https://registry.terraform.io/v1/providers/spectrocloud/spectrocloud/versions"
if curl -s "$VERSION_URL" | grep -q '"version":"${{ env.VERSION_NUMBER }}"'; then
echo "✅ Provider version ${{ env.VERSION_NUMBER }} found in Terraform Registry"
else
echo "⚠️ Provider version ${{ env.VERSION_NUMBER }} not found in Terraform Registry"
echo "Available versions:"
curl -s "$VERSION_URL" | grep -o '"version":"[^"]*"' | head -10
echo "Continuing anyway - version may be published soon..."
fi
- name: Run make commands for provider generation
id: make_generate
continue-on-error: true
run: |
echo "Running make submodules..."
make submodules
echo "Running make vendor..."
make vendor
echo "Running make vendor.check..."
make vendor.check
echo "Running make generate..."
make generate
- name: Handle generation failure
if: steps.make_generate.outcome == 'failure'
run: |
echo "⚠️ make generate failed. Displaying terraform logs:"
if [ -f ".work/terraform-workdir/terraform-logs.txt" ]; then
echo "=== Terraform Logs ==="
cat .work/terraform-workdir/terraform-logs.txt
else
echo "No terraform logs found at .work/terraform-workdir/terraform-logs.txt"
find . -name "terraform-logs.txt" -type f 2>/dev/null || echo "No terraform-logs.txt found anywhere"
fi
echo ""
echo "⚠️ This usually means the provider version ${{ env.VERSION_NUMBER }} is not yet available in the Terraform Registry."
echo "The provider may need to be published first before this workflow can complete."
echo ""
echo "Options:"
echo "1. Wait for the provider version to be published to the Terraform Registry"
echo "2. Check if the version number is correct"
echo "3. If the schema hasn't changed significantly, you can manually copy config/schema.json from a previous version"
exit 1
- name: Run go mod tidy
run: go mod tidy
- name: Run make reviewable and test
run: |
echo "Running make reviewable..."
make reviewable
echo "Running make test..."
make test
- name: Check for changes
id: changes
run: |
if git diff --quiet; then
echo "No changes detected after generation"
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "Changes detected after generation"
echo "has_changes=true" >> $GITHUB_OUTPUT
fi
- name: Commit changes
if: steps.changes.outputs.has_changes == 'true'
run: |
git add .
git commit -m "Bump Terraform Provider version to ${{ env.VERSION }}
- Updated TERRAFORM_PROVIDER_VERSION to ${{ env.VERSION_NUMBER }} in Makefile
- Regenerated provider code and dependencies
- Updated go modules and ran make reviewable test
This automated update ensures compatibility with Terraform Provider ${{ env.VERSION }}"
- name: Push branch
if: steps.changes.outputs.has_changes == 'true'
run: |
if [[ "${{ env.USE_EXISTING_BRANCH }}" == "true" ]]; then
git push origin "${{ env.BRANCH_NAME }}"
echo "Pushed updates to existing branch: ${{ env.BRANCH_NAME }}"
else
git push origin "${{ env.BRANCH_NAME }}"
echo "Pushed new branch: ${{ env.BRANCH_NAME }}"
fi
- name: Create Pull Request
if: steps.changes.outputs.has_changes == 'true' && env.USE_EXISTING_BRANCH == 'false'
uses: actions/github-script@v7
with:
script: |
const { data: pullRequest } = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Bump Terraform Provider to ${{ env.VERSION }}`,
head: '${{ env.BRANCH_NAME }}',
base: 'main',
body: `## 🚀 Terraform Provider Version Bump
This PR automatically updates the Terraform Provider version to **${{ env.VERSION }}**.
### Changes Made:
- ✅ Updated \`TERRAFORM_PROVIDER_VERSION\` to \`${{ env.VERSION_NUMBER }}\` in Makefile
- ✅ Ran \`go install golang.org/x/tools/cmd/goimports@latest\`
- ✅ Executed \`make submodules vendor vendor.check\`
- ✅ Regenerated provider with \`make generate\`
- ✅ Updated dependencies with \`go mod tidy\`
- ✅ Validated changes with \`make reviewable test\`
### Verification Steps:
The following commands were executed successfully:
\`\`\`bash
go install golang.org/x/tools/cmd/goimports@latest
make submodules vendor vendor.check
make generate
go mod tidy
make reviewable test
\`\`\`
### Review Checklist:
- [ ] Verify the version update is correct
- [ ] Check that all generated files are properly updated
- [ ] Ensure tests pass
- [ ] Validate no breaking changes introduced
---
*This PR was automatically created by the \`Bump Terraform Provider Version\` workflow.*`
});
console.log(`Created PR #${pullRequest.number}: ${pullRequest.html_url}`);
- name: Summary
run: |
if [[ "${{ steps.changes.outputs.has_changes }}" == "true" ]]; then
if [[ "${{ env.USE_EXISTING_BRANCH }}" == "true" ]]; then
echo "✅ Successfully updated existing branch '${{ env.BRANCH_NAME }}' with Terraform Provider ${{ env.VERSION }}"
echo "🔗 Changes pushed to existing branch - check the existing PR if applicable"
else
echo "✅ Successfully created branch '${{ env.BRANCH_NAME }}' and PR for Terraform Provider ${{ env.VERSION }}"
echo "🔗 Check the Pull Requests tab to review and merge the changes"
fi
else
echo "ℹ️ No changes were needed - the version might already be up to date"
fi