Skip to content

feat(gha)!: use composite action for semantic release (#692) #741

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions Dockerfile

This file was deleted.

47 changes: 16 additions & 31 deletions action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,8 @@ eval_boolean_action_input() {
}

# Copy inputs into correctly-named environment variables
export GH_TOKEN="${INPUT_GITHUB_TOKEN}"
export PATH="${PATH}:/semantic-release/.venv/bin"
export GIT_COMMITTER_NAME="${INPUT_GIT_COMMITTER_NAME:="github-actions"}"
export GIT_COMMITTER_EMAIL="${INPUT_GIT_COMMITTER_EMAIL:="github-actions@github.com"}"
export SSH_PRIVATE_SIGNING_KEY="${INPUT_SSH_PRIVATE_SIGNING_KEY}"
export SSH_PUBLIC_SIGNING_KEY="${INPUT_SSH_PUBLIC_SIGNING_KEY}"
source ~/semantic-release/.venv/bin/activate
export GIT_COMMIT_AUTHOR="${GIT_COMMITTER_NAME} <${GIT_COMMITTER_EMAIL}>"
export ROOT_OPTIONS="${INPUT_ROOT_OPTIONS:="-v"}"
export PRERELEASE="${INPUT_PRERELEASE:="false"}"
export COMMIT="${INPUT_COMMIT:="false"}"
export PUSH="${INPUT_PUSH:="false"}"
export CHANGELOG="${INPUT_CHANGELOG:="false"}"
export VCS_RELEASE="${INPUT_VCS_RELEASE:="false"}"

# Convert inputs to command line arguments
export ARGS=()
Expand All @@ -49,28 +38,24 @@ ARGS+=("$(eval_boolean_action_input "vcs_release" "$VCS_RELEASE" "--vcs-release"
# Handle --patch, --minor, --major
# https://stackoverflow.com/a/47541882
valid_force_levels=("patch" "minor" "major")
if [ -z "$INPUT_FORCE" ]; then
if [ -z "$FORCE" ]; then
true # do nothing if 'force' input is not set
elif printf '%s\0' "${valid_force_levels[@]}" | grep -Fxzq "$INPUT_FORCE"; then
ARGS+=("--$INPUT_FORCE")
elif printf '%s\0' "${valid_force_levels[@]}" | grep -Fxzq "$FORCE"; then
ARGS+=("--$FORCE")
else
printf "Error: Input 'force' must be one of: %s\n" "${valid_force_levels[@]}" >&2
fi

if [ -n "$INPUT_BUILD_METADATA" ]; then
ARGS+=("--build-metadata $INPUT_BUILD_METADATA")
if [ -n "$BUILD_METADATA" ]; then
ARGS+=("--build-metadata $BUILD_METADATA")
fi

# Change to configured directory
cd "${INPUT_DIRECTORY}"
cd "${DIRECTORY}"

# Set Git details
git config --global user.name "$GIT_COMMITTER_NAME"
git config --global user.email "$GIT_COMMITTER_EMAIL"

# See https://github.com/actions/runner-images/issues/6775#issuecomment-1409268124
# and https://github.com/actions/runner-images/issues/6775#issuecomment-1410270956
git config --system --add safe.directory "*"
git config user.name "$GIT_COMMITTER_NAME"
git config user.email "$GIT_COMMITTER_EMAIL"

if [[ -n $SSH_PUBLIC_SIGNING_KEY && -n $SSH_PRIVATE_SIGNING_KEY ]]; then
echo "SSH Key pair found, configuring signing..."
Expand All @@ -82,16 +67,16 @@ if [[ -n $SSH_PUBLIC_SIGNING_KEY && -n $SSH_PRIVATE_SIGNING_KEY ]]; then
chmod 600 ~/.ssh/signing_key && chmod 600 ~/.ssh/signing_key.pub
eval "$(ssh-agent)"
ssh-add ~/.ssh/signing_key
git config --global gpg.format ssh
git config --global user.signingKey ~/.ssh/signing_key
git config --global commit.gpgsign true
git config --global user.email $GIT_COMMITTER_EMAIL
git config --global user.name $GIT_COMMITTER_NAME
git config gpg.format ssh
git config user.signingKey ~/.ssh/signing_key
git config commit.gpgsign true
git config user.email $GIT_COMMITTER_EMAIL
git config user.name $GIT_COMMITTER_NAME
touch ~/.ssh/allowed_signers
echo "$GIT_COMMITTER_EMAIL $SSH_PUBLIC_SIGNING_KEY" >~/.ssh/allowed_signers
git config --global gpg.ssh.allowedSignersFile ~/.ssh/allowed_signers
git config gpg.ssh.allowedSignersFile ~/.ssh/allowed_signers
fi

# Run Semantic Release
/semantic-release/.venv/bin/python \
~/semantic-release/.venv/bin/python \
-m semantic_release ${ROOT_OPTIONS} version ${ARGS[@]}
35 changes: 32 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ inputs:
required: false
git_committer_email:
description: "The email address for the “committer” field"
default: "github-actions@github.com"
default: "action@github.com"
required: false
ssh_public_signing_key:
description: "The ssh public key used to sign commits"
Expand Down Expand Up @@ -88,17 +88,46 @@ inputs:

outputs:
released:
value: ${{ steps.semrel.outputs.released }}
description: |
"true" if a release was made, "false" otherwise

version:
value: ${{ steps.semrel.outputs.released }}
description: |
The newly released version if one was made, otherwise the current version

tag:
value: ${{ steps.semrel.outputs.tag }}
description: |
The Git tag corresponding to the version output

runs:
using: "docker"
image: "Dockerfile"
using: "composite"
steps:
- run: echo "${{ github.action_path }}" >> $GITHUB_PATH
shell: bash
- run: |
python -m venv ~/semantic-release/.venv
source ~/semantic-release/.venv/bin/activate
pip install python-semantic-release
semantic-release --help
shell: bash
- run: action.sh
id: semrel
shell: bash
env:
GH_TOKEN: ${{ inputs.github_token }}
GIT_COMMITTER_NAME: ${{ inputs.git_committer_name }}
GIT_COMMITTER_EMAIL: ${{ inputs.git_committer_email }}
SSH_PRIVATE_SIGNING_KEY: ${{ inputs.ssh_private_signing_key }}
SSH_PUBLIC_SIGNING_KEY: ${{ inputs.ssh_public_signing_key }}
ROOT_OPTIONS: ${{ inputs.root_options }}
PRERELEASE: ${{ inputs.prerelease }}
COMMIT: ${{ inputs.commit }}
PUSH: ${{ inputs.push }}
CHANGELOG: ${{ inputs.changelog }}
VCS_RELEASE: ${{ inputs.vcs_release }}
FORCE: ${{ inputs.force }}
BUILD_METADATA: ${{ inputs.build_metadata }}
DIRECTORY: ${{ inputs.directory }}