Document initialization options (#2464) #60
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@v4 | |
name: Checkout | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@v1 | |
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 [email protected] | |
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@v7 | |
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@v7 | |
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"], | |
}); |