Skip to content
Merged
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
17 changes: 4 additions & 13 deletions shopware-version/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ inputs:
description: The head reference for pull requests (defaults to github.head_ref)
required: false
default: ""
shopware-github-token:
description: Token used for checking out the shopware repository
github-token:
description: GitHub token used to authenticate gh api calls (defaults to github.token)
required: false
default: ""
default: ${{ github.token }}

outputs:
shopware-version:
Expand All @@ -39,11 +39,6 @@ outputs:
runs:
using: "composite"
steps:
- shell: bash
if: ${{ inputs.shopware-github-token }}
run: |
git config --global "http.https://github.com/${{ inputs.repo || 'shopware/shopware' }}".extraheader "AUTHORIZATION: basic $(echo -n "x-access-token:${{ inputs.shopware-github-token }}" | base64 -w0)"

- name: Get shopware version
id: get-version
shell: bash
Expand All @@ -54,9 +49,5 @@ runs:
REPO: "${{ inputs.repo || 'shopware/shopware' }}"
CURRENT_REPO: "${{ github.repository }}"
FALLBACK: "${{ inputs.fallback || 'trunk' }}"
GH_TOKEN: "${{ inputs.github-token }}"
run: ${GITHUB_ACTION_PATH}/shopware-version.bash

- shell: bash
if: ${{ inputs.shopware-github-token }}
run: |
git config --global --unset "http.https://github.com/${{ inputs.repo || 'shopware/shopware' }}".extraheader
36 changes: 16 additions & 20 deletions shopware-version/shopware-version.bash
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ echo "ref: ${REF}"
get_base_ref "${ORIGINAL_REF}"
echo "base ref: ${BASE_REF}"

# if REPO does not start with https add https://github.com/
if [[ "${REPO}" != https://* ]]; then
REPO="https://github.com/${REPO}"
fi
# Normalize REPO to owner/repo format for gh api
REPO="${REPO#"https://github.com/"}"

ref_exists() {
local branch="${1#"refs/heads/"}"
gh api "repos/${REPO}/git/refs/heads/${branch}" --silent >/dev/null 2>&1
}

# Algo for finding the matching branch in another repo
# 1. if REF exists in target repo, use it
Expand All @@ -68,9 +71,8 @@ fi
# to get the next major from a patch branch replace last two parts with x

echo "Step 1: Checking if REF '${REF}' exists in target repo '${REPO}'"
remote_ref=$(git ls-remote --heads "${REPO}" "${REF}" | cut -f 2)
if [[ -n "${remote_ref}" ]]; then
version="${remote_ref#"refs/heads/"}"
if ref_exists "${REF}"; then
version="${REF#"refs/heads/"}"
echo "✓ Found matching REF: ${version}"
else
BASE_REF=${BASE_REF// /}
Expand All @@ -81,35 +83,29 @@ else

echo "✗ REF not found, checking BASE_REF '${BASE_REF}'"
# Check if BASE_REF exists in target repo
remote_ref=$(git ls-remote --heads "${REPO}" "${BASE_REF}" | cut -f 2)
if [[ -n "${remote_ref}" ]]; then
version="${remote_ref#"refs/heads/"}"
if ref_exists "${BASE_REF}"; then
version="${BASE_REF#"refs/heads/"}"
echo "✓ Found matching BASE_REF: ${version}"
else
echo "✗ BASE_REF not found, checking next minor branch"
# Check next minor branch (replace last digit with x)
next_minor=$(echo "${BASE_REF}" | sed -E 's/[0-9]+$/x/')
echo " Checking next minor: ${next_minor}"
remote_ref=$(git ls-remote --heads "${REPO}" "${next_minor}" | cut -f 2)
if [[ -n "${remote_ref}" ]]; then
version="${remote_ref#"refs/heads/"}"
if ref_exists "${next_minor}"; then
version="${next_minor#"refs/heads/"}"
echo "✓ Found matching next minor: ${version}"
else
echo "✗ Next minor not found, checking next major branch"
# Check next major branch (replace last two digits with x)
next_major=$(echo "${BASE_REF}" | sed -E 's/[0-9]+\.[0-9]+$/x/')
echo " Checking next major: ${next_major}"
remote_ref=$(git ls-remote --heads "${REPO}" "${next_major}" | cut -f 2)

if [[ -n "${remote_ref}" ]]; then
version="${remote_ref#"refs/heads/"}"
if ref_exists "${next_major}"; then
version="${next_major#"refs/heads/"}"
echo "✓ Found matching next major: ${version}"
else
echo "✗ No matching branch found, checking fallback: ${FALLBACK}"

fallback_ref=$(git ls-remote --heads "${REPO}" "${FALLBACK}" | cut -f 2)
if [[ -n "${fallback_ref}" ]]; then
# Use fallback
if ref_exists "${FALLBACK}"; then
version="${FALLBACK}"
echo "✓ Found matching fallback: ${FALLBACK}"
fi
Expand Down