Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add options for token override, draft releases and supplying release tag #37

Merged
merged 10 commits into from
Sep 19, 2023
30 changes: 26 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
name: "release extension"
description: "Generate a release for a precompiled gh extension"
inputs:
gpg_fingerprint:
description: "GPG fingerprint to use for signing releases"
build_script_override:
description: "Path to custom build script for producing binaries to upload"
draft_release:
description: "Create a draft release"
github_token:
description: "GitHub token to use, defaults to github.token if unspecified"
go_version:
description: "The Go version to use for compiling (supports semver spec and ranges)"
default: "1.18"
gpg_fingerprint:
description: "GPG fingerprint to use for signing releases"
release_tag_override:
andyfeller marked this conversation as resolved.
Show resolved Hide resolved
description: "Existing tag that the release should be created from"
branding:
color: purple
icon: box
Expand All @@ -18,10 +24,26 @@ runs:
- uses: actions/setup-go@v3
with:
go-version: ${{ inputs.go_version }}

- id: determine_token
run: |
if [ -n "$INPUT_TOKEN" ]; then
token=$INPUT_TOKEN
else
token=$DEFAULT_TOKEN
fi
echo "TOKEN=$token" >> "$GITHUB_OUTPUT"
env:
DEFAULT_TOKEN: ${{ github.token }}
INPUT_TOKEN: ${{ inputs.github_token }}
shell: bash

- run: ${GITHUB_ACTION_PATH//\\//}/build_and_release.sh
env:
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_TOKEN: ${{ github.token }}
GH_EXT_BUILD_SCRIPT: ${{ inputs.build_script_override }}
GITHUB_TOKEN: ${{ steps.determine_token.outputs.TOKEN }}
GPG_FINGERPRINT: ${{ inputs.gpg_fingerprint }}
GH_EXT_BUILD_SCRIPT: ${{ inputs.build_script_override }}
GH_RELEASE_TAG: ${{ inputs.release_tag_override }}
DRAFT_RELEASE: ${{ inputs.draft_release }}
shell: bash
12 changes: 10 additions & 2 deletions build_and_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ platforms=(
windows-arm64
)

if [[ $GITHUB_REF = refs/tags/* ]]; then
if [ -n "$GH_RELEASE_TAG" ]; then
andyfeller marked this conversation as resolved.
Show resolved Hide resolved
echo "invoking release tag override $GH_RELEASE_TAG"
andyfeller marked this conversation as resolved.
Show resolved Hide resolved
tag="$GH_RELEASE_TAG"
elif [[ $GITHUB_REF = refs/tags/* ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manue1 : Could you elaborate on this approach versus deriving the tag from the reference? Is there an example you can share that showcases a concrete example and how others might benefit from this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a use case for an upcoming CLI extension where the code resides in one repo and has the built binaries published to another separate repo. (see workflow)

Our current plan is to trigger the release manually by dispatching the workflow since it would follow the GHES release window. Instead of creating a release tag in the source repo we'd therefore solely create the tag in the destination repo and GITHUB_REF would therefore not be set when the workflow is run.

I'm also unsure if this is a use case that many others will benefit from. 🤔

tag="${GITHUB_REF#refs/tags/}"
else
tag="$(git describe --tags --abbrev=0)"
Expand All @@ -29,6 +32,11 @@ if [[ $tag = *-* ]]; then
prerelease="--prerelease"
fi

draft_release=""
if [[ "$DRAFT_RELEASE" = "true" ]]; then
draft_release="--draft"
fi

if [ -n "$GH_EXT_BUILD_SCRIPT" ]; then
echo "invoking build script override $GH_EXT_BUILD_SCRIPT"
./"$GH_EXT_BUILD_SCRIPT" "$tag"
Expand Down Expand Up @@ -73,5 +81,5 @@ if gh release view "$tag" >/dev/null; then
gh release upload "$tag" --clobber -- "${assets[@]}"
else
echo "creating release and uploading assets..."
gh release create "$tag" $prerelease --title="${GITHUB_REPOSITORY#*/} ${tag#v}" --generate-notes -- "${assets[@]}"
gh release create "$tag" $prerelease $draft_release --title="${GITHUB_REPOSITORY#*/} ${tag#v}" --generate-notes -- "${assets[@]}"
fi