Skip to content

Commit e312d5e

Browse files
authored
Merge pull request #83 from humanmade/backport-82-to-v6-branch
[Backport v6-branch] Add module release actions
2 parents c5f0479 + aa304c9 commit e312d5e

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Altis Module Auto Release On Manual Tags
2+
3+
on:
4+
push:
5+
tags:
6+
- '*.0.0'
7+
- '*.0.0-beta*'
8+
- '*.0.0-rc*'
9+
10+
jobs:
11+
release:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: actions/github-script@v5
16+
with:
17+
script: |
18+
const tag = '${{ github.ref }}'.replace( 'refs/tags/', '' );
19+
const [
20+
_,
21+
baseTag,
22+
majorVersion,
23+
stability,
24+
preReleaseVersion,
25+
] = tag.match( /^((\d+)\.\d+\.\d+)(?:-(beta|rc)\.?(\d+)?)?/ )
26+
27+
let nameSuffix = '';
28+
if ( stability ) {
29+
nameSuffix = stability === 'beta' ? 'Beta' : 'Release Candidate';
30+
nameSuffix = ' ' + nameSuffix + ' ' + preReleaseVersion;
31+
}
32+
33+
// Create new release from tag.
34+
await github.request( `POST /repos/${{ github.repository }}/releases`, {
35+
name: `${ baseTag }${ nameSuffix }`,
36+
tag_name: tag,
37+
target_commitish: `v${ majorVersion }-branch`,
38+
generate_release_notes: true,
39+
prerelease: !! stability,
40+
} );
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Altis Module Auto Tagging
2+
3+
on:
4+
push:
5+
branches:
6+
- v*-branch*
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/[email protected]
14+
- run: npm install semver
15+
- uses: actions/github-script@v5
16+
with:
17+
script: |
18+
const semver = require( 'semver' );
19+
const [ owner, repo ] = '${{ github.repository }}'.split( '/' );
20+
const [
21+
ref,
22+
branch,
23+
branchVersion,
24+
isRC
25+
] = '${{ github.ref }}'.match( /^refs\/heads\/(v(\d+)-branch(-rc)?)/ );
26+
const tags = await github.paginate( github.rest.git.listMatchingRefs, {
27+
owner,
28+
repo,
29+
ref: `tags/${ branchVersion }${ isRC ? '' : '.0' }.`,
30+
} );
31+
32+
// Start from lowest possible tag.
33+
const initialTag = isRC ? `${ branchVersion }.1.0-rc.1` : `${ branchVersion }.0.0-beta.1`;
34+
35+
// Find the latest tag from results.
36+
const newTag = tags.reduce( ( carry, tag ) => {
37+
const cleanTag = semver.clean( tag.ref.replace( 'refs/tags/', '' ) );
38+
let nextTag = '';
39+
if ( semver.prerelease( cleanTag ) ) {
40+
nextTag = semver.inc( cleanTag, 'prerelease' );
41+
} else {
42+
nextTag = semver.inc( cleanTag, 'patch' );
43+
}
44+
return semver.gt( nextTag, carry ) ? nextTag : carry;
45+
}, initialTag );
46+
47+
const isPreRelease = semver.prerelease( newTag );
48+
49+
// Don't make new Pre-Release tags once we already have one.
50+
if ( isPreRelease && ! isRC && newTag !== initialTag ) {
51+
return;
52+
}
53+
54+
const baseTag = `${ semver.major( newTag ) }.${ semver.minor( newTag ) }.${ semver.patch( newTag ) }`;
55+
let nameSuffix = '';
56+
if ( isPreRelease ) {
57+
nameSuffix = isRC ? 'Preview Release' : isPreRelease.join( ' ' );
58+
nameSuffix = ' ' + nameSuffix;
59+
}
60+
61+
// Create new tag.
62+
await github.request( `POST /repos/${{ github.repository }}/releases`, {
63+
name: `${ baseTag }${ nameSuffix }`,
64+
tag_name: newTag,
65+
target_commitish: branch,
66+
generate_release_notes: true,
67+
prerelease: !! isPreRelease,
68+
} );

0 commit comments

Comments
 (0)