Generated v16.1.0.rc.1 #54
Workflow file for this run
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 CI | |
| on: | |
| push: | |
| tags: | |
| - "release/v*" | |
| jobs: | |
| prepare_release: | |
| name: Prepare release metadata | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.meta.outputs.version }} | |
| dry_run: ${{ steps.meta.outputs.dry_run }} | |
| prerelease: ${{ steps.meta.outputs.prerelease }} | |
| publish_tag: ${{ steps.meta.outputs.publish_tag }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| with: | |
| path: main | |
| - name: Setup Ruby | |
| uses: ruby/setup-ruby@v1 | |
| with: | |
| ruby-version: "3.1" | |
| bundler-cache: true | |
| - name: Compute and validate release metadata | |
| id: meta | |
| working-directory: ./main | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| TAG="${GITHUB_REF_NAME#release/}" | |
| TAG_VALUE="${TAG#v}" | |
| VERSION="${TAG_VALUE%-dry}" | |
| if [[ ! "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.][[:alpha:]][[:alnum:]]*([.][0-9]+)?)?$ ]]; then | |
| echo "Tag version (${VERSION}) is not a valid RubyGems version" >&2 | |
| exit 1 | |
| fi | |
| DRY_RUN=0 | |
| if [ "${TAG_VALUE}" != "${VERSION}" ]; then | |
| DRY_RUN=1 | |
| fi | |
| RUBY_VERSION="$(ruby -Ilib -e 'require "fastly/version"; print Fastly::VERSION')" | |
| echo "Tag version: ${VERSION}" | |
| echo "Ruby version: ${RUBY_VERSION}" | |
| if [ "${VERSION}" != "${RUBY_VERSION}" ]; then | |
| echo "Tag version (${VERSION}) does not match Fastly::VERSION (${RUBY_VERSION})" >&2 | |
| exit 1 | |
| fi | |
| # RubyGems prerelease versions contain letters, e.g. 16.0.1.beta.0 | |
| if [[ "${VERSION}" =~ [[:alpha:]] ]]; then | |
| PRERELEASE=true | |
| else | |
| PRERELEASE=false | |
| fi | |
| PUBLISH_TAG=latest | |
| if [[ "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.([[:alpha:]][[:alnum:]]*)(\.[0-9]+)?$ ]]; then | |
| PUBLISH_TAG="${BASH_REMATCH[1]}" | |
| fi | |
| echo "version=${VERSION}" >> "$GITHUB_OUTPUT" | |
| echo "dry_run=${DRY_RUN}" >> "$GITHUB_OUTPUT" | |
| echo "prerelease=${PRERELEASE}" >> "$GITHUB_OUTPUT" | |
| echo "publish_tag=${PUBLISH_TAG}" >> "$GITHUB_OUTPUT" | |
| publish_rubygems: | |
| name: Publish to RubyGems | |
| runs-on: ubuntu-latest | |
| needs: prepare_release | |
| if: ${{ needs.prepare_release.outputs.dry_run != '1' }} | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| with: | |
| persist-credentials: false | |
| - name: Setup Ruby | |
| uses: ruby/setup-ruby@v1 | |
| with: | |
| ruby-version: "3.1" | |
| bundler-cache: true | |
| - name: Publish gem with trusted publishing | |
| uses: rubygems/release-gem@v1 | |
| create_github_release: | |
| name: Create GitHub release | |
| runs-on: ubuntu-latest | |
| needs: | |
| - prepare_release | |
| - publish_rubygems | |
| if: ${{ needs.prepare_release.outputs.dry_run != '1' }} | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| with: | |
| path: main | |
| - name: Setup Ruby | |
| uses: ruby/setup-ruby@v1 | |
| with: | |
| ruby-version: "3.1" | |
| bundler-cache: true | |
| - name: Fetch published gem from RubyGems | |
| id: fetch | |
| working-directory: ./main | |
| shell: bash | |
| env: | |
| VERSION: ${{ needs.prepare_release.outputs.version }} | |
| PRERELEASE: ${{ needs.prepare_release.outputs.prerelease }} | |
| run: | | |
| set -euo pipefail | |
| FETCH_ARGS=(fastly --version "${VERSION}") | |
| if [ "${PRERELEASE}" = "true" ]; then | |
| FETCH_ARGS+=(--prerelease) | |
| fi | |
| for i in 1 2 3 4 5; do | |
| if gem fetch "${FETCH_ARGS[@]}"; then | |
| break | |
| fi | |
| echo "Fetch attempt ${i} failed; retrying..." | |
| sleep 10 | |
| done | |
| PACKAGE_FILENAME="$(ls -1 fastly-"${VERSION}"*.gem | head -n 1)" | |
| if [ -z "${PACKAGE_FILENAME}" ]; then | |
| echo "Failed to fetch published gem for version ${VERSION}" >&2 | |
| exit 1 | |
| fi | |
| mkdir -p "${GITHUB_WORKSPACE}/dist" | |
| mv "${PACKAGE_FILENAME}" "${GITHUB_WORKSPACE}/dist/${PACKAGE_FILENAME}" | |
| echo "package_filename=${PACKAGE_FILENAME}" >> "$GITHUB_OUTPUT" | |
| - name: Write release body file | |
| shell: bash | |
| env: | |
| API_CLIENT_NAME: Ruby | |
| PACKAGE_REPO_NAME: RubyGems | |
| VERSION: ${{ needs.prepare_release.outputs.version }} | |
| DRY_RUN: "0" | |
| PUBLISH_TAG: ${{ needs.prepare_release.outputs.publish_tag }} | |
| PACKAGE_FILENAME: ${{ steps.fetch.outputs.package_filename }} | |
| run: | | |
| set -euo pipefail | |
| CODE_PATH=./main ./main/.github/scripts/release_body.sh > ./dist/release_body.txt | |
| - name: Create GitHub release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| name: v${{ needs.prepare_release.outputs.version }} | |
| body_path: ./dist/release_body.txt | |
| files: ./dist/${{ steps.fetch.outputs.package_filename }} | |
| draft: false | |
| prerelease: ${{ needs.prepare_release.outputs.prerelease == 'true' }} |