|
| 1 | +name: Isolated Release Gem |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: Optional release version overriding the checked-in version in the standard workflow. |
| 8 | + type: string |
| 9 | + gemspec: |
| 10 | + description: Optional gemspec path; defaults to the only root gemspec. |
| 11 | + type: string |
| 12 | + rubygems-owner: |
| 13 | + description: Optional RubyGems account ID for first publication with a pending trusted publisher. |
| 14 | + type: string |
| 15 | + git-user-name: |
| 16 | + description: Author name for release and next development iteration commits. |
| 17 | + type: string |
| 18 | + default: github-actions[bot] |
| 19 | + git-user-email: |
| 20 | + description: Author email for release and next development iteration commits. |
| 21 | + type: string |
| 22 | + default: github-actions[bot]@users.noreply.github.com |
| 23 | + ruby-version: |
| 24 | + description: Ruby version used to validate, build, and publish. |
| 25 | + type: string |
| 26 | + required: true |
| 27 | + timezone: |
| 28 | + description: Timezone for release dates and Git timestamps. |
| 29 | + type: string |
| 30 | + default: UTC |
| 31 | + validate: |
| 32 | + description: Unprivileged command validating release preconditions; must exit nonzero on failure. |
| 33 | + type: string |
| 34 | + default: bundle exec rake release:validate |
| 35 | + prepare: |
| 36 | + description: Unprivileged command to prepare release files; INPUT_VERSION is the selected release version. |
| 37 | + type: string |
| 38 | + default: bundle exec rake release:prepare |
| 39 | + test: |
| 40 | + description: Unprivileged command to test the prepared release. |
| 41 | + type: string |
| 42 | + default: bundle exec rake |
| 43 | + |
| 44 | +concurrency: |
| 45 | + group: ruby-gem-release-${{ github.repository }} |
| 46 | + cancel-in-progress: false |
| 47 | + |
| 48 | +jobs: |
| 49 | + build: |
| 50 | + runs-on: ubuntu-latest |
| 51 | + permissions: |
| 52 | + contents: read |
| 53 | + outputs: |
| 54 | + artifact: ${{ steps.name_release_artifact.outputs.artifact }} |
| 55 | + env: |
| 56 | + INPUT_VERSION: ${{ inputs.version }} |
| 57 | + INPUT_GEMSPEC_PATH: ${{ inputs.gemspec }} |
| 58 | + DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} |
| 59 | + GIT_USER_NAME: ${{ inputs.git-user-name }} |
| 60 | + GIT_USER_EMAIL: ${{ inputs.git-user-email }} |
| 61 | + TZ: ${{ inputs.timezone }} |
| 62 | + steps: |
| 63 | + - uses: actions/checkout@v7 |
| 64 | + id: checkout |
| 65 | + with: |
| 66 | + fetch-depth: 0 |
| 67 | + persist-credentials: false |
| 68 | + - uses: ruby/setup-ruby@v1 |
| 69 | + id: setup_ruby |
| 70 | + with: |
| 71 | + ruby-version: ${{ inputs.ruby-version }} |
| 72 | + bundler-cache: true |
| 73 | + - name: Capture Release Context |
| 74 | + id: capture_release_context |
| 75 | + env: |
| 76 | + RELEASE_STEP_ID: capture_release_context |
| 77 | + run: bundle exec rake release:workflow:capture |
| 78 | + - name: Validate Release |
| 79 | + id: validate_release |
| 80 | + env: |
| 81 | + RELEASE_COMMAND: ${{ inputs.validate }} |
| 82 | + RELEASE_STEP_ID: validate_release |
| 83 | + RELEASE_STEPS_JSON: ${{ toJSON(steps) }} |
| 84 | + run: bash -euo pipefail -c "$RELEASE_COMMAND" |
| 85 | + - name: Prepare Release |
| 86 | + id: prepare_release |
| 87 | + env: |
| 88 | + RELEASE_COMMAND: ${{ inputs.prepare }} |
| 89 | + RELEASE_STEP_ID: prepare_release |
| 90 | + RELEASE_STEPS_JSON: ${{ toJSON(steps) }} |
| 91 | + run: bash -euo pipefail -c "$RELEASE_COMMAND" |
| 92 | + - name: Resolve Prepared Version |
| 93 | + id: resolve_prepared_version |
| 94 | + env: |
| 95 | + RELEASE_STEP_ID: resolve_prepared_version |
| 96 | + run: bundle exec rake release:workflow:resolve |
| 97 | + - name: Test Release |
| 98 | + id: test_release |
| 99 | + env: |
| 100 | + RELEASE_COMMAND: ${{ inputs.test }} |
| 101 | + RELEASE_STEP_ID: test_release |
| 102 | + RELEASE_STEPS_JSON: ${{ toJSON(steps) }} |
| 103 | + run: bash -euo pipefail -c "$RELEASE_COMMAND" |
| 104 | + - name: Checkpoint Release |
| 105 | + id: checkpoint_release |
| 106 | + env: |
| 107 | + RELEASE_STEP_ID: checkpoint_release |
| 108 | + run: bundle exec rake release:workflow:checkpoint |
| 109 | + - name: Seal Release |
| 110 | + id: seal_release |
| 111 | + env: |
| 112 | + RELEASE_STEP_ID: seal_release |
| 113 | + run: bundle exec rake release:workflow:seal |
| 114 | + - name: Name Release Artifact |
| 115 | + id: name_release_artifact |
| 116 | + run: echo "artifact=release-gem-$RELEASE_VERSION-${{ github.run_id }}-${{ github.run_attempt }}" >> "$GITHUB_OUTPUT" |
| 117 | + - name: Preserve Release Artifacts |
| 118 | + id: preserve_release_artifacts |
| 119 | + uses: actions/upload-artifact@v7 |
| 120 | + with: |
| 121 | + name: ${{ steps.name_release_artifact.outputs.artifact }} |
| 122 | + path: | |
| 123 | + ${{ runner.temp }}/release.gem |
| 124 | + ${{ runner.temp }}/release.json |
| 125 | + ${{ runner.temp }}/release.bundle |
| 126 | + ${{ runner.temp }}/publication.json |
| 127 | + if-no-files-found: error |
| 128 | + retention-days: 30 |
| 129 | + publish: |
| 130 | + needs: build |
| 131 | + runs-on: ubuntu-latest |
| 132 | + environment: release |
| 133 | + permissions: |
| 134 | + contents: write |
| 135 | + id-token: write |
| 136 | + env: |
| 137 | + DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} |
| 138 | + RELEASE_AUTH_MODE: rubygems |
| 139 | + RUBYGEMS_OWNER_ID: ${{ inputs.rubygems-owner }} |
| 140 | + GH_TOKEN: ${{ github.token }} |
| 141 | + steps: |
| 142 | + - uses: actions/checkout@v7 |
| 143 | + id: checkout |
| 144 | + with: |
| 145 | + path: source |
| 146 | + fetch-depth: 0 |
| 147 | + - uses: actions/checkout@v7 |
| 148 | + id: checkout_library |
| 149 | + with: |
| 150 | + repository: ${{ job.workflow_repository }} |
| 151 | + ref: ${{ job.workflow_sha }} |
| 152 | + path: library |
| 153 | + persist-credentials: false |
| 154 | + - uses: ruby/setup-ruby@v1 |
| 155 | + id: setup_ruby |
| 156 | + with: |
| 157 | + ruby-version: ${{ inputs.ruby-version }} |
| 158 | + bundler: none |
| 159 | + - uses: actions/download-artifact@v8 |
| 160 | + id: download_release_artifacts |
| 161 | + with: |
| 162 | + name: ${{ needs.build.outputs.artifact }} |
| 163 | + path: ${{ runner.temp }} |
| 164 | + - name: Publish Release |
| 165 | + id: publish_release |
| 166 | + working-directory: source |
| 167 | + run: ruby --disable-gems -rrubygems -I ../library/lib -rruby-gem-release/workflow/isolated_publication -e 'RubyGemRelease::Workflow::IsolatedPublication.new.publish!' |
0 commit comments