mirror of
https://github.com/reecetech/version-increment.git
synced 2025-12-21 06:25:44 +00:00
Add use_api feature
So that you don't _need_ to checkout (clone) the repo to the worker
This commit is contained in:
@@ -26,6 +26,10 @@ inputs:
|
|||||||
description: 'Specify a non-default branch to use for the release tag (the one without -pre)'
|
description: 'Specify a non-default branch to use for the release tag (the one without -pre)'
|
||||||
required: false
|
required: false
|
||||||
type: string
|
type: string
|
||||||
|
use_api:
|
||||||
|
description: 'Use the GitHub API to discover current tags, which avoids the need for a git checkout, but requires `curl` and `jq`'
|
||||||
|
required: false
|
||||||
|
default: false
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
current-version:
|
current-version:
|
||||||
@@ -69,7 +73,9 @@ runs:
|
|||||||
run: ${{ github.action_path }}/version-lookup.sh
|
run: ${{ github.action_path }}/version-lookup.sh
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
env:
|
||||||
|
github_token: ${{ github.token }}
|
||||||
scheme: ${{ inputs.scheme }}
|
scheme: ${{ inputs.scheme }}
|
||||||
|
use_api: ${{ inputs.use_api }}
|
||||||
|
|
||||||
- id: version-increment
|
- id: version-increment
|
||||||
run: ${{ github.action_path }}/version-increment.sh
|
run: ${{ github.action_path }}/version-increment.sh
|
||||||
@@ -77,6 +83,8 @@ runs:
|
|||||||
env:
|
env:
|
||||||
current_version: ${{ steps.version-lookup.outputs.CURRENT_VERSION }}
|
current_version: ${{ steps.version-lookup.outputs.CURRENT_VERSION }}
|
||||||
increment: ${{ inputs.increment }}
|
increment: ${{ inputs.increment }}
|
||||||
|
github_token: ${{ github.token }}
|
||||||
pep440: ${{ inputs.pep440 }}
|
pep440: ${{ inputs.pep440 }}
|
||||||
scheme: ${{ inputs.scheme }}
|
scheme: ${{ inputs.scheme }}
|
||||||
release_branch: ${{ inputs.release_branch }}
|
release_branch: ${{ inputs.release_branch }}
|
||||||
|
use_api: ${{ inputs.use_api }}
|
||||||
|
|||||||
14
shared.sh
14
shared.sh
@@ -27,6 +27,20 @@ if [[ "${pep440}" != 'false' && "${pep440}" != 'true' ]] ; then
|
|||||||
input_errors='true'
|
input_errors='true'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
use_api="${use_api:-false}"
|
||||||
|
if [[ "${use_api}" != 'false' && "${use_api}" != 'true' ]] ; then
|
||||||
|
echo "🛑 Value of 'use_api' is not valid, choose from 'false' or 'true'" 1>&2
|
||||||
|
input_errors='true'
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "${use_api}" == 'true' ]] ; then
|
||||||
|
if [[ -z "${github_token:-}" ]] ; then
|
||||||
|
echo "🛑 'use_api' is true, but environment variable 'github_token' is not set" 1>&2
|
||||||
|
input_errors='true'
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
##==----------------------------------------------------------------------------
|
##==----------------------------------------------------------------------------
|
||||||
## MacOS compatibility - for local testing
|
## MacOS compatibility - for local testing
|
||||||
|
|
||||||
|
|||||||
@@ -28,20 +28,34 @@ fi
|
|||||||
## Git info - branch names, commit short ref
|
## Git info - branch names, commit short ref
|
||||||
|
|
||||||
default_branch='main'
|
default_branch='main'
|
||||||
# if we're _not_ testing, then _actually_ check the origin
|
|
||||||
if [[ -z "${BATS_VERSION:-}" ]] ; then
|
|
||||||
default_branch="$(git remote show origin | ${grep} 'HEAD branch' | cut -d ' ' -f 5)"
|
|
||||||
fi
|
|
||||||
# use release_branch if not empty
|
# use release_branch if not empty
|
||||||
if [[ -n "${release_branch:-}" ]] ; then
|
if [[ -n "${release_branch:-}" ]] ; then
|
||||||
default_branch="${release_branch}"
|
default_branch="${release_branch}"
|
||||||
|
elif [[ -z "${BATS_VERSION:-}" ]] ; then
|
||||||
|
# if we're _not_ testing, then _actually_ check the origin
|
||||||
|
if [[ "${use_api:-}" == 'true' ]] ; then
|
||||||
|
default_branch="$(
|
||||||
|
curl -fsSL \
|
||||||
|
-H "Accept: application/vnd.github+json" \
|
||||||
|
-H "Authorization: Bearer ${github_token}" \
|
||||||
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||||
|
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}" \
|
||||||
|
| jq -r '.default_branch'
|
||||||
|
)"
|
||||||
|
else
|
||||||
|
default_branch="$(git remote show origin | ${grep} 'HEAD branch' | cut -d ' ' -f 5)"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
current_ref="${GITHUB_REF:-}"
|
current_ref="${GITHUB_REF:-}"
|
||||||
git_commit="$(git rev-parse --short HEAD | sed 's/0*//')" # trim leading zeros, because semver doesn't allow that in
|
|
||||||
# the 'pre-release version' part, but we can't use the + char
|
if [[ "${use_api:-}" == 'true' ]] ; then
|
||||||
# to make it 'build metadata' as that's not supported in K8s
|
# because we cannot use `rev-parse` with the API, we'll take a punt that 9 characters is enough for uniqueness
|
||||||
# labels
|
# shellcheck disable=SC2001
|
||||||
|
git_commit="$(echo "${GITHUB_SHA:0:9}" | sed 's/0*//')" # Also, trim leading zeros, because semver doesn't allow that in
|
||||||
|
else # the 'pre-release version' part, but we can't use the + char
|
||||||
|
git_commit="$(git rev-parse --short HEAD | sed 's/0*//')" # to make it 'build metadata' as that's not supported in K8s
|
||||||
|
fi # labels
|
||||||
|
|
||||||
##==----------------------------------------------------------------------------
|
##==----------------------------------------------------------------------------
|
||||||
## Version increment
|
## Version increment
|
||||||
|
|||||||
@@ -25,16 +25,33 @@ fi
|
|||||||
##==----------------------------------------------------------------------------
|
##==----------------------------------------------------------------------------
|
||||||
## Get tags from GitHub repo
|
## Get tags from GitHub repo
|
||||||
|
|
||||||
# Skip if testing, otherwise pull tags
|
# Skip if testing, or if use_api is true, otherwise pull tags
|
||||||
if [[ -z "${BATS_VERSION:-}" ]] ; then
|
if [[ -z "${BATS_VERSION:-}" ]] ; then
|
||||||
git fetch --quiet --force origin 'refs/tags/*:refs/tags/*'
|
if [[ "${use_api:-}" != 'true' ]] ; then
|
||||||
|
git fetch --quiet --force origin 'refs/tags/*:refs/tags/*'
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
##==----------------------------------------------------------------------------
|
##==----------------------------------------------------------------------------
|
||||||
## Version parsing
|
## Version parsing
|
||||||
|
|
||||||
# detect current version - removing "v" from start of tag if it exists
|
# detect current version - removing "v" from start of tag if it exists
|
||||||
current_version="$(git tag -l | { ${grep} -P "${pcre_allow_vprefix}" || true; } | sed 's/^v//g' | sort -V | tail -n 1)"
|
if [[ "${use_api:-}" == 'true' ]] ; then
|
||||||
|
current_version="$(
|
||||||
|
curl -fsSL \
|
||||||
|
-H "Accept: application/vnd.github+json" \
|
||||||
|
-H "Authorization: Bearer ${github_token}" \
|
||||||
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
||||||
|
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/git/matching-refs/tags/" \
|
||||||
|
| jq -r '.[].ref' | sed 's|refs/tags/||g' \
|
||||||
|
| { ${grep} -P "${pcre_allow_vprefix}" || true; } | sed 's/^v//g' | sort -V | tail -n 1
|
||||||
|
)"
|
||||||
|
else
|
||||||
|
current_version="$(
|
||||||
|
git tag -l \
|
||||||
|
| { ${grep} -P "${pcre_allow_vprefix}" || true; } | sed 's/^v//g' | sort -V | tail -n 1
|
||||||
|
)"
|
||||||
|
fi
|
||||||
|
|
||||||
# support transition from an old reecetech calver style (yyyy-mm-Rr, where R is the literal `R`, and r is the nth release for the month)
|
# support transition from an old reecetech calver style (yyyy-mm-Rr, where R is the literal `R`, and r is the nth release for the month)
|
||||||
if [[ -z "${current_version:-}" ]] ; then
|
if [[ -z "${current_version:-}" ]] ; then
|
||||||
|
|||||||
Reference in New Issue
Block a user