Skip to content

Prerelease

Prerelease #228

Workflow file for this run

name: Prerelease
on:
# Run Every Wednesday at 01:00 AM UTC
schedule:
- cron: '0 2 * * 3'
workflow_dispatch:
inputs:
release-as-patch:
description: "Patch Release (default: Minor)"
type: boolean
default: false
skip-tests:
description: "Skip the E2E test suite for break-glass scenarios"
type: boolean
default: false
permissions: write-all
jobs:
run-tests:
name: Run Tests
uses: ./.github/workflows/test.yml
with:
# need to use contains because inputs are null for schedule runs
skip-e2e-tests: ${{ contains(inputs.skip-tests, 'true') }}
secrets: inherit
permissions:
contents: read
prerelease:
name: Prerelease
needs: [run-tests]
runs-on: ubuntu-latest
steps:
- uses: hashicorp/setup-terraform@v3
- name: Checkout Repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
fetch-depth: 0
token: ${{ secrets.HCP_SDK_PIPELINE_TOKEN }}
- name: Setup Go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
cache: true
go-version-file: 'go.mod'
cache-dependency-path: go.sum
- name: Configure Git
env:
TOKEN: ${{ secrets.HCP_SDK_PIPELINE_TOKEN }}
run: |
git config --global advice.detachedHead false
git config --global url."https://${TOKEN}:x-oauth-basic@github.com/".insteadOf "https://github.com/"
git config user.name "hashicorp-cloud"
git config user.email "hashicorp-cloud@hashicorp.com"
- name: Install Dependencies
env:
GOPRIVATE: 'github.com/hashicorp/*'
run: |
go install github.com/hashicorp/go-changelog/cmd/changelog-build@522d403eacf1dca87cacec6dbc37fdfcda262d26
go mod tidy
- name: Check For Changes
id: changes
run: |
CURRENT_VERSION=$(git describe --tags `git rev-list --tags --max-count=1`)
DIFF_CONTENT=$(git diff $CURRENT_VERSION origin/main)
if [[ $DIFF_CONTENT == "" ]]; then
echo "There were no changes since the last release."
echo "There were no changes since the last release." >> $GITHUB_STEP_SUMMARY
echo "HAS_CHANGES=false" >> $GITHUB_OUTPUT
else
echo "There were changes since the last release."
echo "HAS_CHANGES=true" >> $GITHUB_OUTPUT
echo "CURRENT_VERSION=$CURRENT_VERSION" >> "$GITHUB_ENV"
fi
- name: Prepare Release
if: steps.changes.outputs.HAS_CHANGES == 'true'
env:
GOPRIVATE: 'github.com/hashicorp/*'
GITHUB_TOKEN: ${{ secrets.HCP_SDK_PIPELINE_TOKEN }}
IS_PATCH: ${{ contains(inputs.release-as-patch, 'true') }}
run: |
CURRENT_VERSION_PARTS=(${CURRENT_VERSION//./ })
MAJOR=${CURRENT_VERSION_PARTS[0]}
MINOR=${CURRENT_VERSION_PARTS[1]}
PATCH=${CURRENT_VERSION_PARTS[2]}
if [[ $IS_PATCH == "true" ]]
then
PATCH=$((PATCH+1))
else
MINOR=$((MINOR+1))
PATCH=0
fi
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
echo "NEW_VERSION=$NEW_VERSION" >> "$GITHUB_ENV"
echo "Current Version is: $CURRENT_VERSION"
echo "New Version will be: $NEW_VERSION"
echo "## Updating ${CURRENT_VERSION} to ${NEW_VERSION}" >> $GITHUB_STEP_SUMMARY
echo "Generating CHANGELOG"
GIT_COMMIT_SHA=$(git rev-parse HEAD)
CHANGELOG=$(changelog-build -changelog-template .changelog/changelog.tmpl -note-template .changelog/note.tmpl -entries-dir .changelog/ -last-release ${CURRENT_VERSION} -this-release ${GIT_COMMIT_SHA})
echo "## ${NEW_VERSION} Changelog" >> $GITHUB_STEP_SUMMARY
if [[ $CHANGELOG == "" ]]; then
echo "Changelog was empty. Add at least one changelog entry to \`.changelog/\`." >> $GITHUB_STEP_SUMMARY
echo "Changelog was empty. Add at least one changelog entry to \`.changelog/\`. Exiting."
exit 1
fi
echo -e "${CHANGELOG}" >> $GITHUB_STEP_SUMMARY
DATE=$(date '+%B %d, %Y')
mv CHANGELOG.md OLD-CHANGELOG.md
echo -e "## ${NEW_VERSION} (${DATE})\n${CHANGELOG}" > CHANGELOG.md
cat OLD-CHANGELOG.md >> CHANGELOG.md
rm -f OLD-CHANGELOG.md
git add CHANGELOG.md
git commit -m 'updated CHANGELOG.md'
echo "Updating Documentation"
CURRENT_VERSION_NUM="${CURRENT_VERSION:1}"
NEW_VERSION_NUM="${NEW_VERSION:1}"
sed -i "s/~> $CURRENT_VERSION_NUM/~> $NEW_VERSION_NUM/g" examples/provider/provider.tf
go generate
git add examples/provider/provider.tf docs/index.md
git commit -m 'updated documentation'
echo "## Diff from Prerelease tasks" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`diff" >> $GITHUB_STEP_SUMMARY
git diff @{upstream} @ >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "Diff from Prerelease tasks:"
git diff @{upstream} @
- name: Release New Version
if: success() && github.ref_name == 'main' && steps.changes.outputs.HAS_CHANGES == 'true'
env:
GITHUB_TOKEN: ${{ secrets.HCP_SDK_PIPELINE_TOKEN }}
run: |
CHANGELOG_URL="https://github.com/hashicorp/terraform-provider-hcp/blob/${NEW_VERSION}/CHANGELOG.md"
git tag -a -m "${NEW_VERSION}" -m "See changelog: ${CHANGELOG_URL}" "${NEW_VERSION}"
echo "Git configuration:"
git config -l
echo "Pushing new commits to remote"
git push
echo "Pushing new tag to remote, which will trigger the Release workflow"
git push --tags