-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HCE-556 Implement Auto Releaser (#128)
* set up auto releaser
- Loading branch information
1 parent
2f52f06
commit 8eb6400
Showing
10 changed files
with
292 additions
and
64 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
```release-note:improvement | ||
Run tests in GitHub Actions instead of Circle CI. | ||
``` | ||
|
||
```release-note:improvement | ||
Upload test coverage artifacts to GitHub Actions job run. | ||
``` | ||
|
||
```release-note:improvement | ||
Set up up auto releaser with test gating. | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{{- if index .NotesByType "breaking-change" -}} | ||
BREAKING CHANGES: | ||
|
||
{{range index .NotesByType "breaking-change" -}} | ||
* {{ template "note" . }} | ||
{{ end -}} | ||
{{- end -}} | ||
|
||
{{- if .NotesByType.security }} | ||
SECURITY: | ||
|
||
{{range .NotesByType.security -}} | ||
* {{ template "note" . }} | ||
{{ end -}} | ||
{{- end -}} | ||
|
||
{{- if .NotesByType.feature }} | ||
FEATURES: | ||
|
||
{{range .NotesByType.feature -}} | ||
* {{ template "note" . }} | ||
{{ end -}} | ||
{{- end -}} | ||
|
||
{{- if .NotesByType.improvement }} | ||
IMPROVEMENTS: | ||
|
||
{{range .NotesByType.improvement -}} | ||
* {{ template "note" . }} | ||
{{ end -}} | ||
{{- end -}} | ||
|
||
{{- if .NotesByType.deprecation }} | ||
DEPRECATIONS: | ||
|
||
{{range .NotesByType.deprecation -}} | ||
* {{ template "note" . }} | ||
{{ end -}} | ||
{{- end -}} | ||
|
||
{{- if .NotesByType.bug }} | ||
BUG FIXES: | ||
|
||
{{range .NotesByType.bug -}} | ||
* {{ template "note" . }} | ||
{{ end -}} | ||
{{- end -}} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{- define "note" -}} | ||
{{.Body}}{{if not (stringHasPrefix .Issue "_")}} [[GH-{{- .Issue -}}](https://github.com/hashicorp/hcp-sdk-go/pull/{{- .Issue -}})]{{end}} | ||
{{- end -}} |
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# This workflow checks that there is either a 'pr/no-changelog' label | ||
# applied to a PR or there is a .changelog/<pr number>.txt file associated | ||
# with a PR for a changelog entry. | ||
--- | ||
name: Changelog Check | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
- synchronize | ||
- labeled | ||
branches: | ||
- main | ||
|
||
jobs: | ||
changelog-check: | ||
name: Changelog Check | ||
# Ignore this check if there is a `pr/no-changelog` label | ||
if: | | ||
!contains(github.event.pull_request.labels.*.name, 'pr/no-changelog') | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 # by default the checkout action doesn't checkout all branches | ||
|
||
- name: Check for changelog entry in diff | ||
run: | | ||
# check if there is a diff in the changelog directory | ||
changelog_files=$(git --no-pager diff --name-only HEAD "$(git merge-base HEAD "origin/${{ github.event.pull_request.base.ref }}")" -- .changelog/${{ github.event.pull_request.number }}.txt) | ||
# If we do not find a file matching the PR # in .changelog/, we fail the check | ||
if [ -z "$changelog_files" ]; then | ||
echo "::error::Did not find a changelog entry named ${{ github.event.pull_request.number }}.txt in .changelog/" | ||
echo "::debug::For reference, refer to the README." | ||
exit 1 | ||
elif grep -q ':enhancement$' $changelog_files; then | ||
# "Enhancement is not a valid type of changelog entry, but it's a common mistake. | ||
echo "::error::Found invalid type (enhancement) in changelog - did you mean improvement?" | ||
exit 1 | ||
elif grep -q ':bugs$' $changelog_files; then | ||
echo "::error::Found invalid type (bugs) in changelog - did you mean bug?" | ||
exit 1 | ||
elif ! grep -q '```release-note:' $changelog_files; then | ||
# People often make changelog files like ```changelog:, which is incorrect. | ||
echo "::error::Changelog file did not contain 'release-note' heading - check formatting." | ||
exit 1 | ||
else | ||
echo "::debug::Found changelog entry in PR!" | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
name: Create Release | ||
|
||
on: | ||
# Run Every Wednesday at 12:00 AM UTC | ||
schedule: | ||
- cron: '0 0 * * 3' | ||
workflow_dispatch: | ||
|
||
permissions: write-all | ||
|
||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
token: ${{ secrets.HCP_SDK_PIPELINE_TOKEN }} | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
cache: true | ||
go-version-file: 'go.mod' | ||
|
||
- 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: Cache Go Dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.cache/go-build | ||
~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: Install Go Binaries | ||
env: | ||
GOPRIVATE: 'github.com/hashicorp/*' | ||
run: | | ||
go install github.com/hashicorp/go-changelog/cmd/changelog-build@6ec9be372335f39c5df27e232c3669db7f5183a5 | ||
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.49.0 | ||
- name: Run Unit Tests and Linter | ||
run: make test-ci | ||
|
||
- name: Upload Coverage Artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: Test Coverage | ||
path: coverage.html | ||
|
||
- name: Release New Version | ||
env: | ||
GOPRIVATE: 'github.com/hashicorp/*' | ||
GITHUB_TOKEN: ${{ secrets.HCP_SDK_PIPELINE_TOKEN }} | ||
run: | | ||
CURRENT_VERSION=$(git describe --tags `git rev-list --tags --max-count=1`) | ||
SHOULD_RELEASE=$(git diff $CURRENT_VERSION main) | ||
if [[ $SHOULD_RELEASE == "" ]]; then | ||
echo "There were no changes since the last release. Skipping auto release."; | ||
else | ||
echo "There were changes since the last release." | ||
echo "Current Version: $CURRENT_VERSION" | ||
CURRENT_VERSION_PARTS=(${CURRENT_VERSION//./ }) | ||
MAJOR=${CURRENT_VERSION_PARTS[0]} | ||
MINOR=${CURRENT_VERSION_PARTS[1]} | ||
PATCH=${CURRENT_VERSION_PARTS[2]} | ||
HEAD_BRANCH="main" | ||
MINOR=$((MINOR+1)) | ||
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}" | ||
echo "updating ${CURRENT_VERSION} to ${NEW_VERSION}" | ||
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}) | ||
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 "creating a new git tag" | ||
CHANGELOG_URL="https://github.com/hashicorp/hcp-sdk-go/blob/${NEW_VERSION}/CHANGELOG.md" | ||
git tag -a -m "${NEW_VERSION}" -m "See changelog: ${CHANGELOG_URL}" "${NEW_VERSION}" | ||
echo "New Version: ${NEW_VERSION}" | ||
echo "Pushing new tag to remote" | ||
git config -l | ||
git push --tags | ||
git push | ||
echo "Generating Release Notes" | ||
sed -n -e "1{/# v /d;}" -e "2{/^$/d;}" -e "/# v$(git describe --abbrev=0 --exclude="$(git describe --abbrev=0 --match='v*.*.*' --tags)" --match='v*.*.*' --tags | tr -d v)/q;p" CHANGELOG.md > release-notes.txt | ||
echo "Creating New Release: ${NEW_VERSION}" | ||
gh release create $NEW_VERSION -F release-notes.txt | ||
fi |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Test | ||
|
||
permissions: | ||
contents: write | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
test: | ||
name: Run Unit Tests and Linter | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
cache: true | ||
go-version-file: 'go.mod' | ||
|
||
- name: Cache Go Dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.cache/go-build | ||
~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: Install Dependencies | ||
run: | | ||
go mod download | ||
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.49.0 | ||
go mod tidy | ||
- name: Run Tests | ||
run: make test-ci | ||
|
||
- name: Upload Coverage Artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: Test Coverage | ||
path: coverage.html |
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
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