Skip to content

Commit

Permalink
Add release-toolkit the hability to release itself (NR-233241) (#187)
Browse files Browse the repository at this point in the history
* feat: add release-toolkit auto-release

* fix tests

* Update .github/workflows/push_pr.yaml

Co-authored-by: Christian <[email protected]>

* change major and minor tags at release

* address pr comments

* fix issues found while testing in the fork

* Update .github/workflows/release.yaml

Co-authored-by: Christian <[email protected]>

* copy and paste leftover

---------

Co-authored-by: Christian <[email protected]>
  • Loading branch information
kang-makes and sigilioso authored Apr 5, 2024
1 parent 918aeb6 commit 1f89237
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 13 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/push_pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,35 @@ jobs:
echo "${target_head} = ${merge_base}"
exit 0
test:
go-test:
name: Run tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: '1.19'
- uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
go-version-file: "go.mod"
- name: Run tests
# CLI autodetects whether it is running on GHA or not. If we let GHA set this to true, as it normally does,
# tests cases where GITHUB_ACTIONS is expected to be unset would fail.
run: GITHUB_ACTIONS=false go test -race ./...

check-changelog:
name: Check changelog
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check if CHANGELOG is valid
uses: ./validate-markdown

static-analysis:
name: Static analysis and linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: '1.19'
go-version-file: "go.mod"
- uses: newrelic/newrelic-infra-checkers@v1
with:
# Use full list of linters, rather than the (default) limited set.
Expand Down
125 changes: 125 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: Release on merge to main
on:
push:
branches:
- main

env:
BOT_NAME: newrelic-coreint-bot
BOT_EMAIL: [email protected]

permissions:
contents: write

jobs:
test-release-needed:
name: Test if release is needed
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
# Validation and generation.
- name: Validate that the markdown is correct
uses: ./validate-markdown
- name: Generate YAML
uses: ./generate-yaml
with:
excluded-dirs: .github

# Check that a release is needed.
- name: Check if the release is empty
id: empty
uses: ./is-empty
- name: Check if the release is held
id: held
uses: ./is-held
- name: Output if the release should be skipped
id: output
shell: bash
run: |
echo "skip=${{ steps.empty.outputs.is-empty == 'true' || steps.held.outputs.is-held == 'true' }}" >> $GITHUB_OUTPUT
outputs:
make-release: ${{ steps.output.outputs.skip != true }}

make-release:
name: Make the release if needed
runs-on: ubuntu-latest
needs: [ test-release-needed ]
if: ${{ needs.test-release-needed.outputs.make-release }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate YAML
uses: ./generate-yaml
with:
excluded-dirs: .github

# Put release toolkit to work.
- name: Link dependencies
uses: ./link-dependencies
- name: Calculate next version
id: version
uses: ./next-version

# Prepare to commit the Changelog.
- name: Configure Git
run: |
git config user.name '${{ env.BOT_NAME }}'
git config user.email '${{ env.BOT_EMAIL }}'
# Create changelog and commit it.
- name: Update the markdown
uses: ./update-markdown
with:
version: ${{ steps.version.outputs.next-version }}
- name: Commit updated changelog
run: |
git add CHANGELOG.md
git commit -m "Update changelog with changes from ${{ steps.version.outputs.next-version }}"
git push -u origin ${{ github.event.repository.default_branch }}
# Create the release from the commit above using only the changelog for this release.
- name: Render the changelog snippet
uses: ./render
with:
version: ${{ steps.version.outputs.next-version }}
- name: Create release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create \
${{ steps.version.outputs.next-version }} \
--title ${{ steps.version.outputs.next-version }} \
--target $(git rev-parse HEAD) \
--notes-file CHANGELOG.partial.md
- name: Move major and major.minor tags to this new commit
run: |
# The release is created above, the repo still does not have the tag available here
git fetch
git pull --tags
# Delete, tag, and push the major tag
git push --delete origin "${{ steps.version.outputs.next-version-major }}" || true # Do not fail if the tag does not exist. It will be created.
git tag --force "${{ steps.version.outputs.next-version-major }}" "${{ steps.version.outputs.next-version }}" # The tag might be deleted upstream bit still exists locally
git push origin "${{ steps.version.outputs.next-version-major }}" # Push only the new tag
# Delete, tag, and push the major.minor tag
git push --delete origin "${{ steps.version.outputs.next-version-major-minor }}" || true # Do not fail if the tag does not exist. It will be created.
git tag --force "${{ steps.version.outputs.next-version-major-minor }}" "${{ steps.version.outputs.next-version }}" # The tag might be deleted upstream bit still exists locally
git push origin "${{ steps.version.outputs.next-version-major-minor }}" # Push only the new tag
notify:
name: Notify if somthing went wrong
runs-on: ubuntu-latest
needs: [ test-release-needed, make-release ]
steps:
- name: Notify failure via Slack
if: ${{ always() && failure() }}
uses: archive/github-actions-slack@master
with:
slack-bot-user-oauth-access-token: ${{ secrets.COREINT_SLACK_TOKEN }}
slack-channel: ${{ secrets.COREINT_SLACK_CHANNEL }}
slack-text: "❌ `${{ github.repository }}`: [release pipeline failed](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})."
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/CHANGELOG.md.bak
/CHANGELOG.md.partial
/changelog.yaml
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

Unreleased section should follow [Release Toolkit](https://github.com/newrelic/release-toolkit#render-markdown-and-update-markdown)
## Unreleased

## v1.0.0 - 2023-11-02

### 🚀 Enhancements
- First release of release toolkit

0 comments on commit 1f89237

Please sign in to comment.