-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (69 loc) · 2.96 KB
/
node-version-bump.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Requires repo secret: PERSONAL_ACCESS_TOKEN with permissions:
# Contents: read and write
# Pull Requests: read and write
name: Node.js Version Bump
on:
workflow_dispatch:
inputs:
increment:
description: 'Increment type'
required: true
type: choice
options:
- patch
- minor
- major
auto-merge:
description: 'Auto-merge pull request?'
required: true
type: boolean
default: true
run-name: '${{ github.workflow }}: incrementing ${{ inputs.increment }}'
jobs:
bump:
runs-on: ubuntu-latest
steps:
# Setup and install
- uses: actions/checkout@v4
- uses: volta-cli/action@v4
- run: npm ci
# Bump the version and commit to the default branch
- id: bump-and-commit
run: |
npm run "bump:${{ inputs.increment }}"
git add --all
USER_EMAIL="${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com"
echo "USER_EMAIL=${USER_EMAIL}" >> "${GITHUB_OUTPUT}"
git config --global user.email "${USER_EMAIL}"
USER_NAME="$(gh api "/users/${GITHUB_ACTOR}" | jq .name -r)"
echo "USER_NAME=${USER_NAME}" >> "${GITHUB_OUTPUT}"
git config --global user.name "${USER_NAME}"
PACKAGE_VERSION="$(jq --raw-output '.version' package.json)"
echo "PACKAGE_VERSION=${PACKAGE_VERSION}" >> "${GITHUB_OUTPUT}"
git commit -m "v${PACKAGE_VERSION}"
env:
GH_TOKEN: ${{ github.token }}
# Create the pull request, and optionally mark it as auto-merge
- id: create-pull-request
uses: peter-evans/create-pull-request@v6
with:
# GitHub won't run workflows off of events from the `github-actions` user
# But also, I want the PR to be created under my name for cosmetic reasons
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
author: ${{ steps.bump-and-commit.outputs.USER_NAME }} <${{ steps.bump-and-commit.outputs.USER_EMAIL }}>
branch: ${{ github.actor }}/${{ steps.bump-and-commit.outputs.PACKAGE_VERSION }}
delete-branch: true
title: v${{ steps.bump-and-commit.outputs.PACKAGE_VERSION }}
assignees: ${{ !inputs.auto-merge && github.repository_owner || '' }}
reviewers: ${{ (!inputs.auto-merge && github.repository_owner != github.actor) && github.repository_owner || '' }}
- if: ${{ steps.create-pull-request.outputs.pull-request-number }}
run: |
{
echo "# v${{ steps.bump-and-commit.outputs.PACKAGE_VERSION }}"
echo ""
echo "${{ steps.create-pull-request.outputs.pull-request-url }}"
} >> "${GITHUB_STEP_SUMMARY}"
- if: ${{ steps.create-pull-request.outputs.pull-request-number && inputs.auto-merge }}
run: gh pr merge "${{ steps.create-pull-request.outputs.pull-request-number }}" --squash --auto
env:
GH_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}