-
Notifications
You must be signed in to change notification settings - Fork 75
144 lines (128 loc) · 6.11 KB
/
switch-branch.yml
File metadata and controls
144 lines (128 loc) · 6.11 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
137
138
139
140
141
142
143
144
name: Switch workflow branches
on:
workflow_dispatch:
inputs:
version:
description: "Version to check"
required: false
# workflow_call:
# inputs:
# version:
# description: 'The next VS Code version'
# type: string
# required: true
# secrets:
# SLACK_WEBHOOK:
# required: true
env:
NEXT_TAG: ${{ github.event.inputs.version }}
jobs:
branch-switch:
# if: github.event.inputs.version || github.event.workflow_run.conclusion != 'failure'
permissions: write-all
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
path: openvscode-releases
token: ${{ secrets.GH_PAT }}
- uses: actions/checkout@v4
with:
path: gitpod
repository: gitpod-io/gitpod
- uses: actions/setup-node@v3
with:
node-version: 20
- run: npm init --yes
- run: npm install semver
- name: Run the branch switch-a-roo
uses: actions/github-script@v7
with:
script: |
const { inc, major, minor } = require('semver');
const fs = require('fs');
const replaceInFile = (file, transform) => {
const text = fs.readFileSync(file, 'utf8');
const transformed = transform(text);
fs.writeFileSync(file, transformed, 'utf-8');
}
const getNextReleaseTag = async () => {
const releaseResult = await github.rest.repos.getLatestRelease({
owner: 'gitpod-io',
repo: 'openvscode-server',
});
return inc(releaseResult.data.tag_name.split("-").at(-1), 'minor');
}
const nextTag = process.env.NEXT_TAG || await getNextReleaseTag();
const branch = `release/${major(nextTag)}.${minor(nextTag)}`;
let branchExists = false;
try {
console.info("Checking for " + branch);
await github.rest.repos.getBranch({
owner: 'microsoft',
repo: 'vscode',
branch,
});
branchExists = true;
console.info(`A release for ${branch} branch does exist already. Changing files...`);
replaceInFile('${{ github.workspace }}/openvscode-releases/.github/workflows/insiders-gp.yml', (object) => {
object = object.replace("'upstream/main'", `'upstream/${branch}'`);
object = object.replace("'gp-code/main'", `'gp-code/${branch}'`);
return object;
});
replaceInFile('${{ github.workspace }}/openvscode-releases/.github/workflows/insiders.yml', (object) => {
object = object.replace("'upstream/main'", `'upstream/${branch}'`);
object = object.replace("'main'", `'${branch}'`);
return object;
});
} catch (e) {
console.info(e);
console.info(`A release branch for ${branch} does not exist. Reverting to main.`);
replaceInFile('${{ github.workspace }}/openvscode-releases/.github/workflows/insiders-gp.yml', (object) => {
object = object.replace(/'upstream\/release\/.{1,5}'/i, "'upstream/main'");
object = object.replace(/'gp-code\/release\/.{1,5}'/i, "'gp-code/main'");
return object;
});
replaceInFile('${{ github.workspace }}/openvscode-releases/.github/workflows/insiders.yml', (object) => {
object = object.replace(/'upstream\/release\/.{1,5}'/i, "'upstream/main'");
object = object.replace(/'release\/.{1,5}'/i, "'main'");
return object;
});
}
// Change the values in the gitpod-io/gitpod repository
if (!fs.existsSync('${{ github.workspace }}/gitpod/.github/workflows/')) {
console.error('Could not find gitpod repo under ${{ github.workspace }}/gitpod. Please clone it in that location.')
process.exit();
}
if (branchExists) {
replaceInFile('${{ github.workspace }}/gitpod/.github/workflows/code-nightly.yml', (object) =>
object.replace(/https:\/\/api.github.com\/repos\/gitpod-io\/openvscode-server\/commits\/gp-code\/release\/\d{1,5}\.\d{1,5}/i, 'https://api.github.com/repos/gitpod-io/openvscode-server/commits/gp-code/main'))
} else {
replaceInFile('${{ github.workspace }}/gitpod/.github/workflows/code-nightly.yml', (object) =>
object.replace('https://api.github.com/repos/gitpod-io/openvscode-server/commits/gp-code/main', `https://api.github.com/repos/gitpod-io/openvscode-server/commits/gp-code/release/${nextTag}`))
}
- name: Commit changes (openvscode-releases)
uses: stefanzweifel/git-auto-commit-action@v4
with:
repository: openvscode-releases
add_options: '--all'
commit_message: "Update release branch"
- name: Create Pull Request (gitpod)
uses: peter-evans/create-pull-request@v4
id: gp-pr
with:
token: ${{ secrets.GH_PAT }}
path: gitpod
commit-message: "code: Update Nightly"
branch: "code-update-nightly"
delete-branch: true
title: "code: Update Nightly"
- name: Set env
run: echo "COMMIT_SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
# - name: Slack Notification
# uses: rtCamp/action-slack-notify@v2
# env:
# SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
# SLACK_COLOR: ${{ job.status }}
# SLACK_TITLE: Began new VS Code Release
# SLACK_MESSAGE: 'Updated openvscode-releases with [${{ env.COMMIT_SHA_SHORT }}](https://github.com/${{ github.repository_owner }}/gitpod/commit/${{ env.COMMIT_SHA_SHORT }}) and created [${{ steps.gp-pr.outputs.pull-request-number }}](${{ steps.gp-pr.outputs.pull-request-url }}) for updating `Code Nightly`.'