Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update release and prelease to our standards
Browse files Browse the repository at this point in the history
prerelease label, use semantic-release

several todos still
tagoro9 committed Sep 16, 2024
1 parent a5b04d3 commit 1aab09f
Showing 2 changed files with 194 additions and 17 deletions.
147 changes: 141 additions & 6 deletions prerelease/action.yaml
Original file line number Diff line number Diff line change
@@ -5,13 +5,22 @@ inputs:
required: false
description: Perform checkout as first step of action
default: "true"
checkout-fetch-depth:
required: false
description: The number of commits to fetch. 0 indicates all history for all branches and tags
default: "0"
create-prerelease:
required: false
description: Whether semantic-release should create a prerelease or do a dry run. This can be useful to set to true when a prerelease requires pushing artifacts semantic-release is in charge of generating
default: "false"
github-token:
description: GitHub token that can checkout the consumer repository as well as create tags/releases against it. e.g. 'secrets.GITHUB_TOKEN'
required: true
go-version:
description: Go version to use for building
required: true
default: 1.17.3
# TODO Could this be replaced by create-prerelease + the presence of the docker credentials?
push-docker-snapshot:
description: If a docker snapshot image is generated, push it to the to the registry
required: false
@@ -22,37 +31,115 @@ inputs:
docker-password:
description: Docker password to push the snapshot image to the registry
required: false
extra-plugins:
required: false
description: Extra plugins for pre-install. You can also specify specifying version range for the extra plugins if you prefer. Defaults to install @open-turo/semantic-release-config.
default: |
@open-turo/semantic-release-config
outputs:
version:
description: Version of the project
value: ${{ steps.release.outputs.version }}
runs:
using: composite
steps:
- name: Set vars
id: source-vars
shell: bash
env:
event_name: ${{ github.event_name }}
dispatch_client_payload_ref: ${{ github.event.client_payload.ref }}
dispatch_client_payload_sha: ${{ github.event.client_payload.sha }}
push_ref_name: ${{ github.ref_name }}
push_sha: ${{ github.sha }}
pull_request_ref_name: ${{ github.event.pull_request.head.ref }}
pull_request_sha: ${{ github.event.pull_request.head.sha }}
run: |
echo "event_name=$event_name"
if [ "$event_name" == "push" ]; then
branch=$push_ref_name
sha=$push_sha
elif [ "$event_name" == "repository_dispatch" ]; then
branch=$dispatch_client_payload_ref
sha=$dispatch_client_payload_sha
elif [ "$event_name" == "pull_request" ]; then
branch=$pull_request_ref_name
sha=$pull_request_sha
else
echo "::error::Unsupported event type '$event_name'"
exit 1
fi
echo "branch=$branch"
echo "branch=$branch" >> $GITHUB_OUTPUT
echo "sha=$sha"
echo "sha=$sha" >> $GITHUB_OUTPUT
- name: Checkout
uses: actions/checkout@v4
if: inputs.checkout-repo == 'true'
with:
fetch-depth: 0
fetch-depth: ${{ inputs.checkout-fetch-depth }}
ref: ${{ steps.source-vars.outputs.branch }}

# Find PR
- uses: 8BitJonny/gh-get-current-pr@3.0.0
id: PR
with:
sha: ${{ steps.source-vars.outputs.sha }}

- id: check-pr
shell: bash
run: |
if [ -z "${{ steps.PR.outputs.number }}" ]; then
echo "pr_found=false" >> $GITHUB_OUTPUT
echo "has_prerelease_label=false" >> $GITHUB_OUTPUT
else
echo "pr_found=true" >> $GITHUB_OUTPUT
echo "has_prerelease_label=${{ contains(toJSON(fromJSON(steps.PR.outputs.pr).labels.*.name), 'prerelease') }}" >> $GITHUB_OUTPUT
fi
git branch
echo "branch: ${{ steps.source-vars.outputs.branch }}"
# Allow the action to download any private dependency in the go library
- name: Authorize
uses: open-turo/action-git-auth@v2
uses: open-turo/action-git-auth@v3
with:
github-personal-access-token: ${{ inputs.github-token }}

- name: Setup tools
## Installs version of golang found in .go-version
uses: open-turo/action-setup-tools@v2
- name: Semantic release
uses: go-semantic-release/action@v1
id: release

- name: Prerelease
id: prerelease
uses: open-turo/actions-release/semantic-release@v5
if: steps.check-pr.outputs.has_prerelease_label == 'true'
with:
branches: '["${{ github.event.repository.default_branch }}", {"name": "${{ steps.source-vars.outputs.branch }}","channel": "next","prerelease": "pr-${{ steps.PR.outputs.number }}.${{ github.run_number }}.${{ github.run_attempt }}"}]'
dry-run: ${{ inputs.create-prerelease == 'false' }}
extra-plugins: ${{ inputs.extra-plugins }}
github-token: ${{ inputs.github-token }}
override-github-ref-name: ${{ steps.source-vars.outputs.branch }}
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
- id: vars
if: steps.check-pr.outputs.has_prerelease_label == 'true'
shell: bash
run: |
echo "version=${{ steps.prerelease.outputs.new-release-version }}" >> $GITHUB_OUTPUT
echo "run-url=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> "$GITHUB_OUTPUT"
- name: Goreleaser
uses: goreleaser/goreleaser-action@v6
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
GOVERSION: ${{ inputs.go-version }}
with:
args: release --snapshot
args: release

- name: Docker login
if: inputs.push-docker-snapshot == 'true'
uses: docker/login-action@v3
@@ -69,3 +156,51 @@ runs:
for image in $DOCKER_IMAGES; do
docker push $image
done
- name: Add new version to summary
shell: bash
if: steps.prerelease.outputs.new-release-published == 'true'
env:
NEW_VERSION: ${{ steps.vars.outputs.version }}
DOCKER_IMAGE: ${{ steps.build-docker.outputs.image-with-tag }}
run: |
echo "::notice::new version: \`${NEW_VERSION}\`"
echo "#### New version: \`${NEW_VERSION}\`" >> $GITHUB_STEP_SUMMARY
echo "#### Docker image: \`${DOCKER_IMAGE}\`" >> $GITHUB_STEP_SUMMARY
- name: Add no new version to summary
shell: bash
if: steps.prerelease.outputs.new-release-published != 'true'
run: |
echo "::notice::no new version"
echo "### New version: 'NONE" >> $GITHUB_STEP_SUMMARY
- name: Check for release notes comment
uses: peter-evans/find-comment@v3
id: fc-prerelease
if: steps.prerelease.outputs.new-release-published == 'true'
with:
issue-number: ${{ steps.PR.outputs.number }}
comment-author: "github-actions[bot]"
body-includes: "<!-- prerelease comment -->"
- name: Delete previous release note
if: steps.fc-prerelease.outputs.comment-id != ''
uses: winterjung/comment@v1
with:
type: delete
comment_id: ${{ steps.fc-prerelease.outputs.comment-id }}
token: ${{ inputs.github-token }}

- name: Upsert build version
if: steps.prerelease.outputs.new-release-published == 'true'
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ steps.PR.outputs.number }}
body: |
<!-- prerelease comment -->
## Prerelease build
**Build version:** `${{ steps.vars.outputs.version }}`
**Docker image:** `${{ steps.build-docker.outputs.image-with-tag }}`
[Build output](${{ steps.vars.outputs.run-url }})
64 changes: 53 additions & 11 deletions release/action.yaml
Original file line number Diff line number Diff line change
@@ -5,13 +5,26 @@ inputs:
required: false
description: Perform checkout as first step of action
default: "true"
checkout-fetch-depth:
required: false
description: The number of commits to fetch. 0 indicates all history for all branches and tags
default: "0"
github-token:
description: GitHub token that can checkout the consumer repository as well as create tags/releases against it. e.g. 'secrets.GITHUB_TOKEN'
required: true
go-version:
description: Go version to use for building
required: true
default: 1.17.3
dry-run:
required: false
description: Whether to run semantic release in `dry-run` mode. It will override the `dryRun` attribute in your configuration file
default: "false"
extra-plugins:
required: false
description: Extra plugins for pre-install. You can also specify specifying version range for the extra plugins if you prefer. Defaults to install @open-turo/semantic-release-config.
default: |
@open-turo/semantic-release-config
outputs:
version:
description: Version of the project
@@ -23,29 +36,58 @@ runs:
uses: actions/checkout@v4
if: inputs.checkout-repo == 'true'
with:
fetch-depth: 0
fetch-depth: ${{ inputs.checkout-fetch-depth }}
persist-credentials: false
- uses: 8BitJonny/gh-get-current-pr@3.0.0
id: PR
with:
sha: ${{ github.event.pull_request.head.sha }}
- name: Branches configuration
id: branches-configuration
shell: bash
run: |
if [ -z "${{ steps.PR.outputs.number }}" ]; then
echo "branches=${{ github.event.repository.default_branch }}" >> $GITHUB_OUTPUT
else
echo "branches=[\"${{ github.event.repository.default_branch }}\", {\"name\": \"${{ github.ref_name }}\",\"channel\": \"next\",\"prerelease\": \"pr-${{ steps.PR.outputs.number }}.${{ github.run_number }}.${{ github.run_attempt }}\"}]" >> $GITHUB_OUTPUT
fi
# Allow the action to download any private dependency in the go library
- name: Authorize
uses: open-turo/action-git-auth@v2
uses: open-turo/action-git-auth@v3
with:
github-personal-access-token: ${{ inputs.github-token }}
- name: Setup tools
## Installs version of golang found in .go-version
uses: open-turo/action-setup-tools@v2
- name: Semantic release
uses: go-semantic-release/action@v1
- name: Release
id: release
uses: open-turo/actions-release/semantic-release@v5
with:
branches: ${{ steps.branches-configuration.outputs.branches }}
dry-run: ${{ inputs.dry-run }}
extra-plugins: ${{ inputs.extra-plugins }}
github-token: ${{ inputs.github-token }}
- name: Fetch tags
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
# Since the release is created with semantic-release, we need to fetch the tags
# TODO Is this really needed
# - name: Fetch tags
# shell: bash
# run: |
# git fetch --tags
# git clean -fd
- name: Set args
id: goreleaser-args
shell: bash
run: |
git fetch --tags
git clean -fd
if [[ "${{ inputs.dry-run }}" == "true" ]]; then
echo "args=--skip-publish" >> $GITHUB_OUTPUT
fi
- name: Goreleaser
uses: goreleaser/goreleaser-action@v6
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
GOPRIVATE: github.com/turo/
# TODO Read this from the .go-version file instead
GOVERSION: ${{ inputs.go-version }}
# TODO Handle the prerelease value? How can we get this out of the semantic-release output?
# This is done in the goreleaser config file with the prerelease: auto option
with:
args: release
args: release ${{ steps.goreleaser-args.outputs.args }}

0 comments on commit 1aab09f

Please sign in to comment.