Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically create PR - version update #20

Merged
merged 27 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c991cf7
ci: add action - create PR of updating version
noritakaIzumi Nov 3, 2024
0af21c8
ci: add action - create new release
noritakaIzumi Nov 3, 2024
ca33a86
ci: create-new-release.yml - tag and create release at the same workflow
noritakaIzumi Nov 3, 2024
74b731e
ci: create-pr-version-update.yml - fix create branch
noritakaIzumi Nov 3, 2024
0ab32f2
ci: create-pr-version-update.yml - permission of contents to write
noritakaIzumi Nov 4, 2024
48af68b
ci: create-pr-version-update.yml - fix job create-pr
noritakaIzumi Nov 4, 2024
b003114
ci: create-pr-version-update.yml - delete remote branch "version-upda…
noritakaIzumi Nov 4, 2024
1275ccc
ci: create-pr-version-update.yml - add missing body to PR
noritakaIzumi Nov 4, 2024
436cb0d
ci: create-pr-version-update.yml - add missing checkout
noritakaIzumi Nov 4, 2024
dad88a2
ci: create-pr-version-update.yml - change PR label name
noritakaIzumi Nov 4, 2024
bb4eebd
ci: create-pr-version-update.yml - manually trigger test workflow
noritakaIzumi Nov 4, 2024
c6c0f24
ci: fix pasting
noritakaIzumi Nov 4, 2024
a13ebf8
ci: create-pr-new-release.yml - close existing PR before create
noritakaIzumi Nov 4, 2024
41e961d
ci: create-pr-new-release.yml - add missing env when triggering a wor…
noritakaIzumi Nov 4, 2024
8668752
ci: create-pr-new-release.yml - add an actions-write permission
noritakaIzumi Nov 4, 2024
4b21e2c
ci: test.yml - add workflow_dispatch trigger
noritakaIzumi Nov 4, 2024
abec3a3
ci: create-pr-new-release.yml - specify branch name when trigger test
noritakaIzumi Nov 4, 2024
9382cb6
ci: create-pr-new-release.yml - create token via GitHub Apps
noritakaIzumi Nov 4, 2024
9f3c6be
ci: create-pr-new-release.yml - fix secret keys
noritakaIzumi Nov 4, 2024
f878bdf
ci: create-pr-new-release.yml - remove step "manually run workflow"
noritakaIzumi Nov 4, 2024
66727cd
ci: create-pr-new-release.yml - add reviewers to PR
noritakaIzumi Nov 4, 2024
fd13fc4
ci: create-pr-new-release.yml - introduce variable "base-branch"
noritakaIzumi Nov 4, 2024
59c7ef7
ci: create-pr-new-release.yml - set assignee to PR
noritakaIzumi Nov 4, 2024
bfc68e6
ci: create-pr-new-release.yml - fix assignee
noritakaIzumi Nov 4, 2024
9351110
ci: create-pr-new-release.yml - fix command
noritakaIzumi Nov 4, 2024
f6b2903
ci: create-pr-new-release.yml - temporarily update version with dev s…
noritakaIzumi Nov 4, 2024
5200526
ci: create-pr-new-release.yml - change trigger to workflow_dispatch
noritakaIzumi Nov 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }}
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- main
workflow_call:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down