-
Notifications
You must be signed in to change notification settings - Fork 14
49 lines (46 loc) · 1.52 KB
/
commit.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
name: Commit Version
on:
push:
branches:
- master
jobs:
version_tag:
name: Commit Version
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Generate next version number
uses: actions/github-script@v6
id: version
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: string
script: |
const fs = require('fs');
const version_from_file = JSON.parse(fs.readFileSync('package.json', 'utf8')).version;
const base_version = version_from_file
.split('.')
.slice(0, 2)
.join('.');
const previous_refs = await github.rest.git.listMatchingRefs({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'tags/v' + base_version + '.'
});
// build_number could also be github.run_attempt
const build_number = previous_refs.data.length;
const version = `${base_version}.${build_number}`;
console.log('Version: ', version);
return version;
- name: Create tag
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/v${{ steps.version.outputs.result }}',
sha: context.sha
})