-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (86 loc) · 3.26 KB
/
Copy pathgithub_actions_master.yml
File metadata and controls
107 lines (86 loc) · 3.26 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
name: github-actions master
on:
push:
branches: [ master ]
paths-ignore:
- '**.md'
jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Create tag and clean up alpha tags
uses: actions/github-script@v4
with:
script: |
const fs = require('fs');
const version = fs.readFileSync('./.version').toString().trim();
const mergedPullRequestsResponse = await github.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
direction: 'desc',
state: 'closed',
per_page: 20,
});
const mergedPullRequest = mergedPullRequestsResponse.data.find(pr => pr.merge_commit_sha == context.sha);
if (!mergedPullRequest) {
core.setFailed('Pull request does not exist');
return;
}
const responseTags = await github.repos.listTags({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100,
})
const tags = responseTags.data.map(tag => tag.name);
const alphaVersion = `${version}-alpha.${mergedPullRequest.number}.`;
const alphaTagsToBeDeleted = tags.filter(tag => tag.startsWith(alphaVersion));
for (const tag of alphaTagsToBeDeleted) {
console.log(`Try to delete tag: ${tag}`);
await github.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${tag}`
})
console.log(`Deleted tag: ${tag}`);
}
await github.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${version}`,
sha: context.sha
});
const versions = version.split('.');
const majorVersion = versions[0];
const majorTag = tags.find(tag => tag == majorVersion);
if (majorTag) {
await github.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${majorTag}`,
})
}
await github.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${majorVersion}`,
sha: context.sha,
});
const majorMinorVersion = `${versions[0]}.${versions[1]}`;
const majorMinorTag = tags.find(tag => tag == majorMinorVersion);
if (majorMinorTag) {
await github.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${majorMinorVersion}`,
})
}
await github.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${majorMinorVersion}`,
sha: context.sha,
});
console.log(`Created tag: ${version}`);
console.log(`Created tag: ${majorVersion}`);
console.log(`Created tag: ${majorMinorVersion}`);