Skip to content

Commit

Permalink
Merge pull request #197 from Cox-Automotive/US852217-automatic-release
Browse files Browse the repository at this point in the history
Automatic release and versioning
  • Loading branch information
DevOpsDave authored Jan 18, 2024
2 parents 09b55f9 + ee65fd6 commit aa15a24
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 43 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/check-for-release-label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# For this check to pass you must have a release label on your PR.
# valid labels are: release/patch, release/minor, release/major, release/skip
name: Check For Release Label

on:
pull_request:
branches: [ master ]

jobs:
check_for_release_label:

runs-on: ubuntu-latest

steps:
- name: Get release label
uses: actions-ecosystem/action-release-label@v1.2.0
id: release-label

- run: echo "Release level is ${{ steps.release-label.outputs.level }}"

- name: Fail if label does not exist, or skip if release/skip label exists
if: ${{ ( ! contains(github.event.pull_request.labels.*.name, 'release/skip') ) && ( steps.release-label.outputs.level == null ) }}
run: echo "Please label your PR with a release label" && exit 1
86 changes: 86 additions & 0 deletions .github/workflows/release-auto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# This GitHub action can publish assets for release when a tag is created.
# Currently its setup to run on any tag that matches the pattern "v*" (ie. v0.1.0).
#
# This uses an action (paultyng/ghaction-import-gpg) that assumes you set your
# private key in the `GPG_PRIVATE_KEY` secret and passphrase in the `PASSPHRASE`
# secret. If you would rather own your own GPG handling, please fork this action
# or use an alternative one for key handling.
#
# You will need to pass the `--batch` flag to `gpg` in your signing step
# in `goreleaser` to indicate this is being used in a non-interactive mode.
#
name: release-auto2

on:
pull_request:
types: [closed]

jobs:
auto-release:
runs-on: ubuntu-latest
if: ${{ github.event.pull_request.merged == true }}
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Unshallow fetch
run: git fetch --prune --unshallow

- name: Get release label
uses: actions-ecosystem/action-release-label@v1
id: release-label
if: ${{ github.event.pull_request.merged == true }}

- name: Get latest tag
uses: actions-ecosystem/action-get-latest-tag@v1
id: get-latest-tag
if: ${{ steps.release-label.outputs.level != null }}

- run: |
echo "Latest tag: ${{ steps.get-latest-tag.outputs.tag }}"
echo "Release level: ${{ steps.release-label.outputs.level }}"
- name: Bump the version
uses: actions-ecosystem/action-bump-semver@v1
id: bump-semver
if: ${{ steps.release-label.outputs.level != null }}
with:
current_version: ${{ steps.get-latest-tag.outputs.tag }}
level: ${{ steps.release-label.outputs.level }}

- run: |
echo "New version: ${{ steps.bump-semver.outputs.new_version }}"
- name: Push new tag
uses: actions-ecosystem/action-push-tag@v1
if: ${{ steps.release-label.outputs.level != null }}
with:
tag: ${{ steps.bump-semver.outputs.new_version }}
message: '${{ steps.bump-semver.outputs.new_version }}: PR #${{ github.event.pull_request.number }} ${{ github.event.pull_request.title }}'

- name: Set up Go
uses: actions/setup-go@v2
if: ${{ steps.release-label.outputs.level != null }}
with:
go-version: 1.18.x

- name: Import GPG key
id: import_gpg
uses: paultyng/ghaction-import-gpg@v2.1.0
if: ${{ steps.release-label.outputs.level != null }}
env:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
PASSPHRASE: ${{ secrets.PASSPHRASE }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
if: ${{ steps.release-label.outputs.level != null }}
with:
version: latest
args: release --clean
env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}



42 changes: 0 additions & 42 deletions .github/workflows/release.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ glide.lock
gpg/

# ignore. For testing we don't want to store a specific provider.
.terraform.lock.hcl
.terraform.lock.hcl

0 comments on commit aa15a24

Please sign in to comment.