-
Notifications
You must be signed in to change notification settings - Fork 241
136 lines (120 loc) · 4.78 KB
/
version_bump.yml
File metadata and controls
136 lines (120 loc) · 4.78 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: Version bump
on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+
workflow_dispatch:
inputs:
version:
description: "The version to bump the Ruby LSP to (e.g.: 0.1.0)"
type: string
required: true
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
name: Checkout
- name: Set up Ruby
uses: ruby/setup-ruby@d5126b9b3579e429dd52e51e68624dda2e05be25 # v1.267.0
with:
bundler-cache: true
cache-version: 1
- name: Automated patch version bump
if: ${{ inputs.version == '' }}
id: version
run: |
version=$(ruby -e 'major, minor, patch = File.read("VERSION").split(".").map(&:to_i)
new_version = "#{major}.#{minor}.#{patch + 1}"
File.write("VERSION", "#{new_version}\n")
print(new_version)')
bundle config unset deployment
bundle install
echo "VERSION=$version" >> "$GITHUB_OUTPUT"
- name: Manual version bump
if: ${{ inputs.version != '' }}
run: |
echo "${{ inputs.version }}" > VERSION
bundle config unset deployment
bundle install
- name: Commit version
run: |
version="${{ inputs.version != '' && inputs.version || steps.version.outputs.VERSION }}"
git config user.name github-actions
git config user.email github-actions@github.com
git checkout -b automated-bump-version-$version
git add VERSION Gemfile.lock
git commit -m "Bump version to v$version"
git push origin automated-bump-version-$version
- name: Open pull request and turn on auto-merge
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
id: open-pr
with:
github-token: "${{ secrets.RUBY_LSP_BOT_TOKEN }}"
result-encoding: string
script: |
const version="${{ inputs.version != '' && inputs.version || steps.version.outputs.VERSION }}"
const response = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
head: `automated-bump-version-${version}`,
base: "main",
title: `Bump version to v${version}`,
body: `This is an automated pull request to eagerly bump the gem version to v${version}.`
});
const pullRequestNumber = response.data.number;
console.log(`Created pull request ${pullRequestNumber}`);
return pullRequestNumber;
- name: Approve pull request
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
script: |
const pullRequestNumber = ${{steps.open-pr.outputs.result}};
const getPullRequestIdQuery = `query GetPullRequestId($owner: String!, $repo: String!, $pullRequestNumber: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $pullRequestNumber) {
id
}
}
}`
const repoInfo = {
owner: context.repo.owner,
repo: context.repo.repo,
pullRequestNumber: pullRequestNumber,
}
await github.rest.pulls.createReview({
pull_number: pullRequestNumber,
owner: context.repo.owner,
repo: context.repo.repo,
event: 'APPROVE',
})
console.log(`Approved pull request ${pullRequestNumber}`);
const enableAutoMergeQuery = `mutation ($pullRequestId: ID!, $mergeMethod: PullRequestMergeMethod!) {
enablePullRequestAutoMerge(input: {
pullRequestId: $pullRequestId,
mergeMethod: $mergeMethod
}) {
pullRequest {
autoMergeRequest {
enabledAt
enabledBy {
login
}
}
}
}
}`
const response = await github.graphql(getPullRequestIdQuery, repoInfo)
const data = {
pullRequestId: response.repository.pullRequest.id,
mergeMethod: 'MERGE',
}
await github.graphql(enableAutoMergeQuery, data)
console.log(`Enabled auto-merge for pull request ${pullRequestNumber}`);
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullRequestNumber,
labels: ["chore"],
});