-
Notifications
You must be signed in to change notification settings - Fork 0
46 lines (37 loc) · 1.53 KB
/
github_actions_branch.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
name: github-actions branch
on:
pull_request:
paths-ignore:
- '**.md'
jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Create tag
uses: actions/github-script@v4
with:
script: |
const fs = require('fs');
const version = fs.readFileSync('./.version').toString().trim();
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 existingTags = tags.filter(tag => tag == version);
if (existingTags.length) {
core.setFailed(`Tag ${version} already exists. Ensure you increment the version within the .version file`);
return;
}
const alphaVersion = `${version}-alpha.${context.issue.number}.`;
const usedAlphaNumbers = tags.filter(tag => tag.startsWith(alphaVersion)).map(tag => parseInt(tag.replace(alphaVersion, ''), 10)).sort();
const newVersion = usedAlphaNumbers.length ? (usedAlphaNumbers[usedAlphaNumbers.length - 1] + 1) : 1;
const response = await github.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${alphaVersion}${newVersion}`,
sha: context.sha
})
console.log(`Created tag: ${alphaVersion}${newVersion}`);