-
Notifications
You must be signed in to change notification settings - Fork 1
64 lines (59 loc) · 2.36 KB
/
downgrade.yaml
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
name: Downgrade
on:
workflow_call:
inputs:
version:
description: Version to downgrade to
type: string
required: true
stage:
description: Stage
type: string
required: true
jobs:
downgrade:
environment: ${{ inputs.stage }}
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
id: branch
with:
result-encoding: string
script: |
const version = '${{ inputs.version }}';
return version.includes('-alpha.') ? 'develop' : version.includes('-beta.') ? 'release' : 'main';
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ steps.branch.outputs.result }}
- uses: actions/github-script@v6
with:
script: |
const version = '${{ inputs.version }}';
const releases = [];
let page = 1;
let count;
do {
const pagedReleases = ((await github.rest.repos.listReleases({ owner: context.repo.owner, repo: context.repo.repo, page, per_page: 100 })).data);
count = pagedReleases.length;
releases.push(...pagedReleases.filter(release => release.name?.startsWith('v20')).map(release => ({
tag: release.tag_name, branch: release.tag_name.includes('-alpha.') ? 'develop' :
release.tag_name.includes('-beta.') ? 'release' : 'main', creation: Date.parse(release.published_at ?? release.created_at), published: !release.draft, id: release.id
})));
page++;
} while (count > 0);
const release = releases.find(r => r.tag === version);
if (release == null) {
core.setFailed(`Version ${version} doesn't exist.`);
return;
}
for (const r of releases.filter(re => re.creation > release.creation)) {
await exec.exec('git', ['push', '--delete', 'origin', r.tag]);
await github.rest.repos.deleteRelease({ owner: context.repo.owner, repo: context.repo.repo, release_id: r.id });
}
- if: inputs.stage != 'alpha'
run: |
git reset --hard ${{ inputs.version }}
git config --global user.name "Noor's GitHub Bot"
git config --global user.email "noorgithubbot@github"
git push --force origin