-
Notifications
You must be signed in to change notification settings - Fork 62
161 lines (140 loc) · 5.73 KB
/
prerelease.yml
File metadata and controls
161 lines (140 loc) · 5.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
name: Prerelease
on:
workflow_dispatch:
inputs:
release-as-patch:
description: "Patch Release (default: Minor)"
type: boolean
default: false
testacc-skip:
description: "Skip Acceptance Tests"
type: boolean
default: false
concurrency:
group: prerelease
cancel-in-progress: false
permissions: write-all
jobs:
test:
name: Run Tests
uses: ./.github/workflows/test.yml
secrets: inherit
testacc:
if: ${{ !inputs.testacc-skip }}
name: Run Acceptance Tests
uses: ./.github/workflows/testacc.yml
secrets: inherit
prerelease:
name: Prerelease
if: always()
needs:
- test
- testacc
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@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.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