diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 81c37f2..02202af 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,7 @@ name: Test actions on: pull_request: + workflow_dispatch: jobs: shopware-version-fallback: @@ -84,4 +85,32 @@ jobs: if [[ "${SHOPWARE_VERSION}" != "${EXPECTED_VERSION}" ]]; then echo "shopware-version should be '${EXPECTED_VERSION}' but got '${SHOPWARE_VERSION}'" exit 1 + fi + + print-versions: + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - name: Checkout code + uses: actions/checkout@v6 + - name: Get versions + id: versions + uses: ./versions + with: + github-token: ${{ github.token }} + - name: Print outputs + run: | + echo "next-minor: ${{ steps.versions.outputs.next-minor }}" + echo "next-patch: ${{ steps.versions.outputs.next-patch }}" + echo "latest: ${{ steps.versions.outputs.latest-version }}" + echo "first: ${{ steps.versions.outputs.first-version }}" + echo "lts-latest: ${{ steps.versions.outputs.lts-latest-version }}" + echo "lts-next-patch: ${{ steps.versions.outputs.lts-next-patch }}" + - name: Sanity-check next-minor + run: | + NEXT_MINOR="${{ steps.versions.outputs.next-minor }}" + if [[ ! "$NEXT_MINOR" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "next-minor looks wrong: '${NEXT_MINOR}'" + exit 1 fi \ No newline at end of file diff --git a/versions/action.yml b/versions/action.yml index 41dd0b2..20c18c7 100644 --- a/versions/action.yml +++ b/versions/action.yml @@ -12,6 +12,9 @@ inputs: lts-major: description: LTS major prefix like v6.5. default: v6.6. + github-token: + description: Token used to check for release branches via the GitHub API + default: ${{ github.token }} outputs: first-version: @@ -47,5 +50,6 @@ runs: env: CUR_MAJOR: ${{ inputs.major }} PREV_MAJOR: ${{ inputs.lts-major }} + GH_TOKEN: ${{ inputs.github-token }} run: | ${GITHUB_ACTION_PATH}/print_versions.bash | tee >> "$GITHUB_OUTPUT" diff --git a/versions/print_versions.bash b/versions/print_versions.bash index 59fa304..3c0ebda 100755 --- a/versions/print_versions.bash +++ b/versions/print_versions.bash @@ -1,5 +1,10 @@ #!/usr/bin/env bash +if ! gh auth status &>/dev/null; then + echo "::error::gh is not authenticated. Set GH_TOKEN or GITHUB_TOKEN." >&2 + exit 1 +fi + PREV_MAJOR="${PREV_MAJOR:-"v6.6."}" CUR_MAJOR="${CUR_MAJOR:-"v6.7."}" @@ -26,7 +31,11 @@ get_next_minor_and_patch() { IFS='.' read -r -a parts <<<"${max_tag}" local next_release_branch="${parts[0]#v}.${parts[1]}.$((${parts[2]} + 1)).x" - if gh api "repos/shopware/shopware/branches/${next_release_branch}" --silent 2>/dev/null; then + local gh_output gh_status + gh_output=$(gh api "repos/shopware/shopware/branches/${next_release_branch}" 2>&1) + gh_status=$? + if [ $gh_status -eq 0 ] || ! echo "$gh_output" | grep -q "HTTP 404"; then + # Branch exists, or the API call failed for an unknown reason — default to freeze. echo "NEXT_MINOR=${parts[0]}.${parts[1]}.$((${parts[2]} + 2)).0" else echo "NEXT_MINOR=${parts[0]}.${parts[1]}.$((${parts[2]} + 1)).0"