From 3251c5c21b6a06a5246b33b3f1c094190dbbe75d Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Thu, 27 Jun 2024 15:22:54 +0200 Subject: [PATCH] Add workflow to automatically create a release --- .github/workflows/release.yml | 14 +++++++------- .github/workflows/update-v1-branch.yml | 15 +++++++++++++++ release.rb | 17 +++++++++++++++++ 3 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/update-v1-branch.yml create mode 100644 release.rb diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8c5de1e..464d939 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,17 +1,17 @@ -name: Update the v1 branch when a release is published +name: Create a Release on: - release: - types: [published] + workflow_dispatch: permissions: - contents: read + contents: write # for creating release jobs: release: runs-on: ubuntu-latest - permissions: - contents: write # for git push steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - - run: git push origin HEAD:v1 + - uses: ./ + with: + ruby-version: '3.3' + - run: ruby release.rb diff --git a/.github/workflows/update-v1-branch.yml b/.github/workflows/update-v1-branch.yml new file mode 100644 index 0000000..f497b72 --- /dev/null +++ b/.github/workflows/update-v1-branch.yml @@ -0,0 +1,15 @@ +name: Update the v1 branch when a release is published +on: + release: + types: [published] +permissions: + contents: write # for git push + +jobs: + update_branch: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - run: git push origin HEAD:v1 diff --git a/release.rb b/release.rb new file mode 100644 index 0000000..4bf822b --- /dev/null +++ b/release.rb @@ -0,0 +1,17 @@ +require 'json' + +def run(command_line) + puts "$ #{command_line}" + output = `#{command_line}` + puts output + raise $?.inspect unless $?.success? + output +end + +latest_release_tag = run 'gh release view --json tagName' +latest_release_tag = JSON.load(latest_release_tag).fetch('tagName') + +raise latest_release_tag unless latest_release_tag =~ /\Av(\d+).(\d+).(\d+)\z/ +tag = "v#{$1}.#{Integer($2)+1}.0" + +run "gh release create --generate-notes --latest #{tag}"