Release Cloudflare SDK Updates #103
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release Cloudflare SDK Updates | |
| on: | |
| schedule: | |
| - cron: '0 6 * * *' | |
| workflow_dispatch: | |
| concurrency: | |
| group: cloudflare-release | |
| cancel-in-progress: true | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v5 | |
| with: | |
| node-version: 24 | |
| cache: npm | |
| - name: Determine Cloudflare versions | |
| id: versions | |
| shell: bash | |
| run: | | |
| set -eo pipefail | |
| current=$(node -e "const pkg=require('./package.json'); process.stdout.write((pkg.dependencies && pkg.dependencies.cloudflare) || '')") | |
| current=${current#^} | |
| current=${current#~} | |
| current=${current#=} | |
| latest=$(npm view cloudflare version) | |
| needs_update=false | |
| if [ -n "$latest" ] && [ "$latest" != "$current" ]; then | |
| needs_update=true | |
| fi | |
| echo "Current Cloudflare version: ${current:-none}" | |
| echo "Latest Cloudflare version: ${latest:-unknown}" | |
| { | |
| printf 'needs_update=%s\n' "$needs_update" | |
| printf 'current=%s\n' "$current" | |
| printf 'latest=%s\n' "$latest" | |
| } >> "$GITHUB_OUTPUT" | |
| - name: Cloudflare dependency is already current | |
| if: steps.versions.outputs.needs_update != 'true' | |
| run: echo "Cloudflare dependency already at v${{ steps.versions.outputs.current }}." | |
| - name: Configure git | |
| if: steps.versions.outputs.needs_update == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| - name: Update Cloudflare dependency | |
| if: steps.versions.outputs.needs_update == 'true' | |
| env: | |
| CLOUDFLARE_VERSION: ${{ steps.versions.outputs.latest }} | |
| run: | | |
| npm install cloudflare@${CLOUDFLARE_VERSION} --save-exact | |
| - name: Install dependencies | |
| if: steps.versions.outputs.needs_update == 'true' | |
| run: npm ci | |
| - name: Build action bundle | |
| if: steps.versions.outputs.needs_update == 'true' | |
| run: npm run build | |
| - name: Commit dependency and build updates | |
| if: steps.versions.outputs.needs_update == 'true' | |
| id: commit | |
| env: | |
| VERSION: ${{ steps.versions.outputs.latest }} | |
| run: | | |
| set -eo pipefail | |
| git add package.json package-lock.json dist | |
| if git diff --cached --quiet; then | |
| echo "No generated changes detected; skipping release." | |
| echo "has_changes=false" >> "$GITHUB_OUTPUT" | |
| else | |
| git commit -m "deps: update cloudflare to v${VERSION}" | |
| echo "has_changes=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Create version tags | |
| if: steps.versions.outputs.needs_update == 'true' && steps.commit.outputs.has_changes == 'true' | |
| id: tagging | |
| env: | |
| VERSION: ${{ steps.versions.outputs.latest }} | |
| run: | | |
| set -eo pipefail | |
| full="v${VERSION}" | |
| # Extract the major version number from VERSION (e.g., "2.3.4" -> "2") | |
| major="v${VERSION%%.*}" | |
| if git rev-parse -q --verify "refs/tags/${full}" >/dev/null; then | |
| echo "Tag ${full} already exists; aborting to prevent overwriting." >&2 | |
| exit 1 | |
| fi | |
| git tag -a "${full}" -m "Release Cloudflare Script Action ${full}" | |
| git tag -fa "${major}" -m "Release Cloudflare Script Action ${full}" | |
| echo "full=${full}" >> "$GITHUB_OUTPUT" | |
| echo "major=${major}" >> "$GITHUB_OUTPUT" | |
| - name: Push changes and tags | |
| if: steps.versions.outputs.needs_update == 'true' && steps.commit.outputs.has_changes == 'true' | |
| env: | |
| FULL_TAG: ${{ steps.tagging.outputs.full }} | |
| MAJOR_TAG: ${{ steps.tagging.outputs.major }} | |
| run: | | |
| set -eo pipefail | |
| git push origin HEAD:master | |
| git push origin "${FULL_TAG}" | |
| git push --force origin "${MAJOR_TAG}" | |
| - name: Create GitHub release | |
| if: steps.versions.outputs.needs_update == 'true' && steps.commit.outputs.has_changes == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const version = '${{ steps.versions.outputs.latest }}'; | |
| const previous = '${{ steps.versions.outputs.current || 'unknown' }}'; | |
| const tag = `v${version}`; | |
| const body = [ | |
| `## Summary`, | |
| `- Update Cloudflare SDK from v${previous} to v${version}`, | |
| '', | |
| `This release was generated automatically when a new Cloudflare SDK version became available.`, | |
| ].join('\n'); | |
| try { | |
| await github.rest.repos.createRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag_name: tag, | |
| name: `Cloudflare Script Action ${tag}`, | |
| body, | |
| }); | |
| } catch (error) { | |
| if (error.status === 422) { | |
| console.log(`Release for ${tag} already exists; skipping.`); | |
| } else { | |
| throw error; | |
| } | |
| } |