From 9c2363e4a7426e003092f6deeb3f23de5c3c83b7 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Fri, 3 May 2024 13:31:57 +0200 Subject: [PATCH 1/3] Remove obsolete task --- .github/workflows/create-next-milestone.yml | 22 ----- .github/workflows/draft-release.yml | 93 --------------------- 2 files changed, 115 deletions(-) delete mode 100644 .github/workflows/create-next-milestone.yml delete mode 100644 .github/workflows/draft-release.yml diff --git a/.github/workflows/create-next-milestone.yml b/.github/workflows/create-next-milestone.yml deleted file mode 100644 index 352f80a7..00000000 --- a/.github/workflows/create-next-milestone.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Create next milestone -on: - milestone: - types: [closed] - -jobs: - create_next_milestone: - permissions: - issues: write - runs-on: ubuntu-latest - steps: - - name: Get next minor version - id: semvers - uses: WyriHaximus/github-action-next-semvers@b135abb108d66990a85e18623d906404f4350ce4 - with: - version: ${{ github.event.milestone.title }} - - name: Create next milestone - uses: WyriHaximus/github-action-create-milestone@ab85332e3150ec018daf497a0f761fe69d52bc7d - with: - title: ${{ steps.semvers.outputs.minor }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml deleted file mode 100644 index b5cbf364..00000000 --- a/.github/workflows/draft-release.yml +++ /dev/null @@ -1,93 +0,0 @@ -name: Draft release on release branch push -on: create - -jobs: - draft_release_notes: - if: github.event.ref_type == 'branch' && startsWith('${{ github.event.ref }}', 'bump_to_version_') - runs-on: ubuntu-latest - steps: - - name: Get release version - id: releaseVersion - uses: actions/github-script@v6 - with: - result-encoding: string - script: | - return '${{ github.event.ref }}'.substring('bump_to_version_'.length); - - name: Get milestone for version - id: milestone - uses: actions/github-script@v6 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - const milestones = await github.paginate(github.rest.issues.listMilestones, { - owner: context.repo.owner, - repo: context.repo.repo, - state: 'all' - }) - - const milestone = milestones.find(milestone => milestone.title == '${{steps.releaseVersion.outputs.result}}') - - if (milestone) { - return milestone.number - } else { - return null - } - - name: Generate release notes - if: fromJSON(steps.milestone.outputs.result) - id: generate - uses: actions/github-script@v6 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - result-encoding: string - script: | - const pullRequests = await github.paginate(github.rest.pulls.list, { - owner: context.repo.owner, - repo: context.repo.repo, - state: 'closed', - base: 'main' - }) - - var draftText = "> Please categorize the following changes:\n\n" - for (let pull of pullRequests) { - if (pull.merged_at && pull.milestone && pull.milestone.number == ${{steps.milestone.outputs.result}}) { - // Skip PR with only `dev/*` labels, as these represent internal changes - if (pull.labels.length > 0 && pull.labels.every(label => label.name.startsWith("dev/"))) { - continue - } - - // Add labels to description, to ease categorization - var lineItem = "* " - for (let label of pull.labels) { - lineItem += label.name.charAt(0).toUpperCase() + label.name.slice(1) + ": " - } - - lineItem += pull.title + " (#" + pull.number + ")" - - // Add author if labeled as 'community' - if (pull.labels.some(label => label.name == "community")) { - lineItem += " (@" + pull.user.login + ")" - } - - draftText += lineItem + "\n" - } - } - draftText += "\n### Added\n\n### Changed\n\n### Fixed\n\n### Removed\n\n" - - // Escape backticks - draftText = draftText.replace(/`/g,"\\`") - - return draftText - - name: Create draft release - if: fromJSON(steps.milestone.outputs.result) - uses: actions/github-script@v6 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - await github.rest.repos.createRelease({ - owner: context.repo.owner, - repo: context.repo.repo, - tag_name: 'v${{ steps.releaseVersion.outputs.result }}', - name: '${{ steps.releaseVersion.outputs.result }}', - draft: true, - body: `${{ steps.generate.outputs.result }}` - }) From 853fb5256d682f9c60bffb323e8c747e4de3abfb Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Fri, 3 May 2024 13:35:44 +0200 Subject: [PATCH 2/3] Update milestone action --- .../add-milestone-to-pull-requests.yml | 56 +++++++++++-------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/.github/workflows/add-milestone-to-pull-requests.yml b/.github/workflows/add-milestone-to-pull-requests.yml index ab6c5ac0..fed57269 100644 --- a/.github/workflows/add-milestone-to-pull-requests.yml +++ b/.github/workflows/add-milestone-to-pull-requests.yml @@ -1,45 +1,53 @@ name: Add milestone to pull requests on: - pull_request_target: + pull_request: types: [closed] - branches: - - main jobs: - add_milestone_to_merged: - permissions: - issues: write - pull-requests: write - if: github.event.pull_request.merged && github.event.pull_request.milestone == null - name: Add milestone to merged pull requests + add_milestone: runs-on: ubuntu-latest + if: github.event.pull_request.merged == true && github.event.pull_request.milestone == null steps: + - name: Checkout code + # Checks out the branch that the pull request is merged into + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.base.ref }} + + - name: Get major version from gemspec + # Parse the gemspec and return the major version + id: version + run: | + echo "::set-output name=version::$(find . -name *.gemspec | ruby -ne 'puts Gem::Specification.load($_.chomp).version.to_s.split(".").first')" + - name: Get project milestones id: milestones - uses: actions/github-script@v6 + uses: actions/github-script@v7 with: github-token: ${{secrets.GITHUB_TOKEN}} script: | - const list = await github.rest.issues.listMilestones({ + const milestones = await github.rest.issues.listMilestones({ owner: context.repo.owner, repo: context.repo.repo, state: 'open' }) - // Need to manually sort because "sort by number" isn't part of the api - // highest number first - const milestones = list.data.sort((a,b) => (b.number - a.number)) + return milestones.data - return milestones.length == 0 ? null : milestones[0].number - name: Update Pull Request - if: steps.milestones.outputs.result != null - uses: actions/github-script@v6 + # Update the merged pull request with the milestone starts with the major version + uses: actions/github-script@v7 with: github-token: ${{secrets.GITHUB_TOKEN}} script: | - // Confusingly, the issues api is used because pull requests are issues - await github.rest.issues.update({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: ${{ github.event.pull_request.number }}, - milestone: ${{ steps.milestones.outputs.result }}, - }); + const milestones = ${{steps.milestones.outputs.result}} + const majorVersion = ${{steps.version.outputs.version}} + const milestone = milestones.find(m => m.title.startsWith(majorVersion)) + + if (milestone) { + await github.rest.issues.update({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: ${{ github.event.pull_request.number }}, + milestone: milestone.number + }) + } From a8fe457395f9fa4d62123430627d65ecca2df24c Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Fri, 3 May 2024 13:37:38 +0200 Subject: [PATCH 3/3] Trusted publishing --- .github/workflows/publish.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..9f4522c4 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,25 @@ +name: Publish Gem + +on: + push: + tags: + - 'v*' + +jobs: + push: + runs-on: ubuntu-latest + + permissions: + contents: write + id-token: write + + environment: release + + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + ruby-version: '3.2.4' + - uses: rubygems/release-gem@v1