Prerelease #242
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
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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.HCP_SDK_PIPELINE_TOKEN }} | |
- name: Setup Go | |
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 | |
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 |