-
Notifications
You must be signed in to change notification settings - Fork 4
68 lines (60 loc) · 2.38 KB
/
module-auto-tagging.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
name: Altis Module Auto Tagging
on:
push:
branches:
- v*-branch*
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/[email protected]
- run: npm install semver
- uses: actions/github-script@v5
with:
script: |
const semver = require( 'semver' );
const [ owner, repo ] = '${{ github.repository }}'.split( '/' );
const [
ref,
branch,
branchVersion,
isRC
] = '${{ github.ref }}'.match( /^refs\/heads\/(v(\d+)-branch(-rc)?)/ );
const tags = await github.paginate( github.rest.git.listMatchingRefs, {
owner,
repo,
ref: `tags/${ branchVersion }${ isRC ? '' : '.0' }.`,
} );
// Start from lowest possible tag.
const initialTag = isRC ? `${ branchVersion }.1.0-rc.1` : `${ branchVersion }.0.0-beta.1`;
// Find the latest tag from results.
const newTag = tags.reduce( ( carry, tag ) => {
const cleanTag = semver.clean( tag.ref.replace( 'refs/tags/', '' ) );
let nextTag = '';
if ( semver.prerelease( cleanTag ) ) {
nextTag = semver.inc( cleanTag, 'prerelease' );
} else {
nextTag = semver.inc( cleanTag, 'patch' );
}
return semver.gt( nextTag, carry ) ? nextTag : carry;
}, initialTag );
const isPreRelease = semver.prerelease( newTag );
// Don't make new Pre-Release tags once we already have one.
if ( isPreRelease && ! isRC && newTag !== initialTag ) {
return;
}
const baseTag = `${ semver.major( newTag ) }.${ semver.minor( newTag ) }.${ semver.patch( newTag ) }`;
let nameSuffix = '';
if ( isPreRelease ) {
nameSuffix = isRC ? 'Preview Release' : isPreRelease.join( ' ' );
nameSuffix = ' ' + nameSuffix;
}
// Create new tag.
await github.request( `POST /repos/${{ github.repository }}/releases`, {
name: `${ baseTag }${ nameSuffix }`,
tag_name: newTag,
target_commitish: branch,
generate_release_notes: true,
prerelease: !! isPreRelease,
} );