From 6cc6a84bc66a56254d4c771afb945e8bbe265813 Mon Sep 17 00:00:00 2001 From: Zackarie Vinckier Date: Wed, 30 Aug 2023 11:11:17 +0200 Subject: [PATCH 1/3] feat: use composite action for semantic release --- Dockerfile | 24 ------------------------ action.sh | 47 ++++++++++++++++------------------------------- action.yml | 31 ++++++++++++++++++++++++++++--- 3 files changed, 44 insertions(+), 58 deletions(-) delete mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index e58dca624..000000000 --- a/Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -# This Dockerfile is only for GitHub Actions -FROM python:3.10-bullseye - -RUN set -ex; \ - apt-get update; \ - apt-get install -y --no-install-recommends \ - git-lfs - -#install backported stable vesion of git, which supports ssh signing -RUN echo "deb http://deb.debian.org/debian bullseye-backports main" >> /etc/apt/sources.list; \ - apt-get update;\ - apt-get install -y git/bullseye-backports - -ENV PYTHONPATH /semantic-release - -COPY . /semantic-release - -RUN cd /semantic-release && \ - python -m venv /semantic-release/.venv && \ - /semantic-release/.venv/bin/pip install . - -RUN /semantic-release/.venv/bin/python -m semantic_release --help - -ENTRYPOINT ["/semantic-release/action.sh"] diff --git a/action.sh b/action.sh index 9429ae9ee..c1e75f5c0 100755 --- a/action.sh +++ b/action.sh @@ -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=() @@ -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..." @@ -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[@]} diff --git a/action.yml b/action.yml index b73baf1d4..ffe64c98d 100644 --- a/action.yml +++ b/action.yml @@ -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" @@ -100,5 +100,30 @@ outputs: 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 + 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 }} From 4ae03bd1532bca5071f1889d4a9157ff8098a77b Mon Sep 17 00:00:00 2001 From: Zackarie Vinckier <32618947+zckv@users.noreply.github.com> Date: Fri, 29 Sep 2023 12:04:29 +0200 Subject: [PATCH 2/3] fix: use value keyword in action.yml This correct the outputs set to none problem. --- action.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/action.yml b/action.yml index ffe64c98d..a265cca00 100644 --- a/action.yml +++ b/action.yml @@ -87,15 +87,18 @@ inputs: Build metadata to append to the new version outputs: + value: ${{ steps.semrel.outputs.released }} 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 @@ -111,6 +114,7 @@ runs: semantic-release --help shell: bash - run: action.sh + id: semrel shell: bash env: GH_TOKEN: ${{ inputs.github_token }} From 318a26bc46240d7a70df19e1c4ac65145b2f243d Mon Sep 17 00:00:00 2001 From: Zackarie Vinckier <32618947+zckv@users.noreply.github.com> Date: Fri, 29 Sep 2023 12:12:47 +0200 Subject: [PATCH 3/3] fix: correct yaml syntaxt --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index a265cca00..9be7973a0 100644 --- a/action.yml +++ b/action.yml @@ -87,8 +87,8 @@ inputs: Build metadata to append to the new version outputs: - value: ${{ steps.semrel.outputs.released }} released: + value: ${{ steps.semrel.outputs.released }} description: | "true" if a release was made, "false" otherwise