generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 1
105 lines (88 loc) · 3.62 KB
/
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
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
name: Bump version
on:
workflow_call:
inputs:
type:
description: Type of release
required: true
type: string
package:
description: Package to release
required: true
type: string
jobs:
version-bump:
name: Bump version
runs-on: ubuntu-22.04
steps:
- name: Check out repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Set up .NET
uses: actions/setup-dotnet@3e891b0cb619bf60e2c25674b222b8940e2c1c25 # v4.1.0
- name: Bump version
id: version-bumper
shell: pwsh
env:
PACKAGE_NAME: ${{ inputs.package }}
BUMP_TYPE: ${{ inputs.type }}
run: |
$NEW_VERSION=$(./scripts/UpdatePackageVersion.ps1 -PackageName $env:PACKAGE_NAME -BumpType $env:BUMP_TYPE)
Write-Output "NEW_VERSION=$NEW_VERSION" >> $Env:GITHUB_OUTPUT
- name: Create PR
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const baseBranch = '${{ github.event.ref }}';
const packageName = '${{ inputs.package }}';
const bumpType = '${{ inputs.type }}';
const newVersion = '${{ steps.version-bumper.outputs.NEW_VERSION }}';
if (newVersion === '') {
core.setFailed('New version was not set.');
return;
}
// Configure Git
await exec.exec(`git config user.name "github-actions"`);
await exec.exec(`git config user.email "[email protected]"`);
const versionBumpBranch = `version-bump/${packageName}-to-${newVersion}`;
await exec.exec(`git checkout -b ${versionBumpBranch}`);
// Skip opening PR if branch already exists on the origin remote since that means it was
// opened earlier and force pushing to the branch updates the existing PR
let shouldOpenPullRequest = true;
try {
await exec.exec(`git ls-remote --exit-code --heads origin ${versionBumpBranch}`);
shouldOpenPullRequest = false;
} catch { }
// Add and commit changes
const commitMessage = `Bump ${packageName} version to ${newVersion}`;
const gitCommitCommand = `git commit --all --message "${commitMessage}"`;
let gitCommitOutput = `$ ${gitCommitCommand}\n\n`;
let gitCommitFailed = false;
try {
await exec.exec(gitCommitCommand, [], {
listeners: {
stdout: function stdout(data) { gitCommitOutput += data },
stderr: function stderr(data) { gitCommitOutput += data }
}
});
} catch (error) {
gitCommitOutput += error;
gitCommitFailed = true;
}
if (gitCommitFailed) {
console.log(`Failed:\n\n${gitCommitOutput}`);
throw new Error("git commit command failed.");
}
await exec.exec(`git push --force --set-upstream origin HEAD:${versionBumpBranch}`);
const pullRequestBody = `
Version Bump for ${packageName} to ${newVersion}
/cc @${{ github.event.sender.login }}
`;
await github.rest.pulls.create({
owner: "bitwarden",
repo: "dotnet-extensions",
title: commitMessage,
body: pullRequestBody,
head: versionBumpBranch,
base: baseBranch,
});
console.log("Successfully opened GitHub PR.");