Skip to content

Commit

Permalink
Automatically create PR - version update (#20)
Browse files Browse the repository at this point in the history
* ci: add action - create PR of updating version

* ci: add action - create new release

* ci: create-new-release.yml - tag and create release at the same workflow

* ci: create-pr-version-update.yml - fix create branch

* ci: create-pr-version-update.yml - permission of contents to write

* ci: create-pr-version-update.yml - fix job create-pr

* ci: create-pr-version-update.yml - delete remote branch "version-update" if exists

* ci: create-pr-version-update.yml - add missing body to PR

* ci: create-pr-version-update.yml - add missing checkout

* ci: create-pr-version-update.yml - change PR label name

* ci: create-pr-version-update.yml - manually trigger test workflow

* ci: fix pasting

* ci: create-pr-new-release.yml - close existing PR before create

* ci: create-pr-new-release.yml - add missing env when triggering a workflow

* ci: create-pr-new-release.yml - add an actions-write permission

* ci: test.yml - add workflow_dispatch trigger

* ci: create-pr-new-release.yml - specify branch name when trigger test

* ci: create-pr-new-release.yml - create token via GitHub Apps

* ci: create-pr-new-release.yml - fix secret keys

* ci: create-pr-new-release.yml - remove step "manually run workflow"

* ci: create-pr-new-release.yml - add reviewers to PR

* ci: create-pr-new-release.yml - introduce variable "base-branch"

* ci: create-pr-new-release.yml - set assignee to PR

* ci: create-pr-new-release.yml - fix assignee

* ci: create-pr-new-release.yml - fix command

* ci: create-pr-new-release.yml - temporarily update version with dev segment

* ci: create-pr-new-release.yml - change trigger to workflow_dispatch
  • Loading branch information
noritakaIzumi authored Nov 4, 2024
1 parent ce70a91 commit 5f202a0
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/create-new-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Create new release

on:
pull_request:
branches:
- main
types:
- closed

jobs:
push-tag:
if: ${{ contains(github.event.pull_request.labels.*.name, 'version update') && github.event.pull_request.merged }}
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.tag.outputs.value }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Hatch
uses: pypa/hatch@install

- name: Configure git
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
- name: Push a tag
id: tag
run: |
tag="v$(hatch version)"
git tag -a ${tag} -m "New release ${tag} (tagged by github-actions[bot])"
git push origin ${tag}
echo "value=${tag}" >> $GITHUB_OUTPUT
create-release:
runs-on: ubuntu-latest
needs: push-tag
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Create a release
uses: elgohr/Github-Release-Action@v5
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
title: ${{ steps.tag.outputs.value }}
tag: ${{ steps.tag.outputs.value }}
89 changes: 89 additions & 0 deletions .github/workflows/create-pr-new-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Create PR (for new release)

on:
workflow_dispatch:
inputs:
segment:
description: increment version method
type: string
required: true
options:
- major # 1.0.0 to 2.0.0
- minor # 1.0.0 to 1.1.0
- micro # 1.0.0 to 1.0.1
- dev # 1.0.0 to 1.0.0dev0

env:
branch-name: "version-update"
base-branch: "main"
reviewers: "noritakaIzumi"

jobs:
commit-and-push:
name: Commit and push
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
new-version: ${{ steps.new-version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ env.base-branch }}

- name: Install Hatch
uses: pypa/hatch@install

- name: Configure git
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
- name: Create branch (after clean)
run: |
git push -d origin ${{ env.branch-name }} || true
git checkout -b ${{ env.branch-name }} ${{ env.base-branch }}
- name: Update version
run: hatch version ${{ inputs.segment }}

- name: Get new version number
id: new-version
run: echo "version=$(hatch version)" >> $GITHUB_OUTPUT

- name: Commit and push
run: |
git commit -am "build: update version to ${{ steps.new-version.outputs.version }}"
git push --set-upstream origin ${{ env.branch-name }}
create-pr:
name: Create a PR
runs-on: ubuntu-latest
permissions:
pull-requests: write
needs:
- commit-and-push
steps:
- name: Checkout repository
uses: actions/checkout@v4

- uses: actions/create-github-app-token@v1
id: generate-token
with:
app-id: ${{ secrets.REPOSITORY_APP_ID }}
private-key: ${{ secrets.REPOSITORY_APP_PRIVATE_KEY }}

- name: Create PR (after clean)
run: |
gh pr close ${{ env.branch-name }} --comment "This PR is deprecated." || true
gh pr create \
--base ${{ env.base-branch }} \
--head ${{ env.branch-name }} \
--title "Update version to ${{ needs.commit-and-push.outputs.new-version }}" \
--body "New release is created after you merge the PR." \
--reviewer ${{ env.reviewers }} \
--assignee ${{ github.actor }} \
--label "new release"
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}

0 comments on commit 5f202a0

Please sign in to comment.