diff --git a/.github/workflows/post-release-templates.yml b/.github/workflows/post-release-templates.yml index 6076d5c214..b370c76d77 100644 --- a/.github/workflows/post-release-templates.yml +++ b/.github/workflows/post-release-templates.yml @@ -13,7 +13,39 @@ env: NEXT_TELEMETRY_DISABLED: 1 # Disable Next telemetry jobs: + wait_for_release: + runs-on: ubuntu-24.04 + outputs: + release_tag: ${{ steps.determine_tag.outputs.release_tag }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + sparse-checkout: .github/workflows + + - name: Determine Release Tag + id: determine_tag + run: | + if [ "${{ github.event_name }}" == "release" ]; then + echo "Using tag from release event: ${{ github.event.release.tag_name }}" + echo "release_tag=${{ github.event.release.tag_name }}" >> "$GITHUB_OUTPUT" + else + # pull latest tag from github, must match any version except v2. Should match v3, v4, v99, etc. + echo "Fetching latest tag from github..." + LATEST_TAG=$(git describe --tags --abbrev=0 --match 'v[0-9]*' --exclude 'v2*') + echo "Latest tag: $LATEST_TAG" + echo "release_tag=$LATEST_TAG" >> "$GITHUB_OUTPUT" + fi + + - name: Wait until latest versions resolve on npm registry + run: | + ./.github/workflows/wait-until-package-version.sh payload ${{ steps.determine_tag.outputs.release_tag }} + ./.github/workflows/wait-until-package-version.sh @payloadcms/translations ${{ steps.determine_tag.outputs.release_tag }} + ./.github/workflows/wait-until-package-version.sh @payloadcms/next ${{ steps.determine_tag.outputs.release_tag }} + update_templates: + needs: wait_for_release runs-on: ubuntu-24.04 permissions: contents: write @@ -25,8 +57,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - with: - fetch-depth: 0 # Needed for tags - name: Setup uses: ./.github/actions/setup @@ -60,20 +90,6 @@ jobs: - name: Update template lockfiles and migrations run: pnpm script:gen-templates - - name: Determine Release Tag - id: determine_tag - run: | - if [ "${{ github.event_name }}" == "release" ]; then - echo "Using tag from release event: ${{ github.event.release.tag_name }}" - echo "release_tag=${{ github.event.release.tag_name }}" >> "$GITHUB_OUTPUT" - else - # pull latest tag from github, must match any version except v2. Should match v3, v4, v99, etc. - echo "Fetching latest tag from github..." - LATEST_TAG=$(git describe --tags --abbrev=0 --match 'v[0-9]*' --exclude 'v2*') - echo "Latest tag: $LATEST_TAG" - echo "release_tag=$LATEST_TAG" >> "$GITHUB_OUTPUT" - fi - - name: Commit and push changes id: commit env: @@ -85,7 +101,7 @@ jobs: git diff --name-only - export BRANCH_NAME=templates/bump-${{ steps.determine_tag.outputs.release_tag }}-$(date +%s) + export BRANCH_NAME=templates/bump-${{ needs.wait_for_release.outputs.release_tag }}-$(date +%s) echo "branch=$BRANCH_NAME" >> "$GITHUB_OUTPUT" - name: Create pull request @@ -94,12 +110,12 @@ jobs: token: ${{ secrets.GH_TOKEN_POST_RELEASE_TEMPLATES }} labels: 'area: templates' author: github-actions[bot] - commit-message: 'templates: bump templates for ${{ steps.determine_tag.outputs.release_tag }}' + commit-message: 'templates: bump templates for ${{ needs.wait_for_release.outputs.release_tag }}' branch: ${{ steps.commit.outputs.branch }} base: main assignees: ${{ github.actor }} - title: 'templates: bump for ${{ steps.determine_tag.outputs.release_tag }}' + title: 'templates: bump for ${{ needs.wait_for_release.outputs.release_tag }}' body: | - 🤖 Automated bump of templates for ${{ steps.determine_tag.outputs.release_tag }} + 🤖 Automated bump of templates for ${{ needs.wait_for_release.outputs.release_tag }} Triggered by user: @${{ github.actor }} diff --git a/.github/workflows/wait-until-package-version.sh b/.github/workflows/wait-until-package-version.sh new file mode 100755 index 0000000000..d4e664e2a2 --- /dev/null +++ b/.github/workflows/wait-until-package-version.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +if [[ "$#" -ne 2 ]]; then + echo "Usage: $0 " + exit 1 +fi + +PACKAGE_NAME="$1" +TARGET_VERSION=${2#v} # Git tag has leading 'v', npm version does not +TIMEOUT=300 # 5 minutes in seconds +INTERVAL=10 # 10 seconds +ELAPSED=0 + +echo "Waiting for version ${TARGET_VERSION} of '${PACKAGE_NAME}' to resolve... (timeout: ${TIMEOUT} seconds)" + +while [[ ${ELAPSED} -lt ${TIMEOUT} ]]; do + latest_version=$(npm show "${PACKAGE_NAME}" version 2>/dev/null) + + if [[ ${latest_version} == "${TARGET_VERSION}" ]]; then + echo "SUCCCESS: Version ${TARGET_VERSION} of ${PACKAGE_NAME} is available." + exit 0 + else + echo "Version ${TARGET_VERSION} of ${PACKAGE_NAME} is not available yet. Retrying in ${INTERVAL} seconds... (elapsed: ${ELAPSED}s)" + fi + + sleep "${INTERVAL}" + ELAPSED=$((ELAPSED + INTERVAL)) +done + +echo "Timed out after ${TIMEOUT} seconds waiting for version ${TARGET_VERSION} of '${PACKAGE_NAME}' to resolve." +exit 1