From ba5b1107969612c9f129392b9dc74b860baced58 Mon Sep 17 00:00:00 2001 From: Robert O'Rourke Date: Mon, 18 Oct 2021 12:29:17 +0000 Subject: [PATCH] Add module release actions --- .github/workflows/module-auto-release.yml | 40 +++++++++++++ .github/workflows/module-auto-tagging.yml | 68 +++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 .github/workflows/module-auto-release.yml create mode 100644 .github/workflows/module-auto-tagging.yml diff --git a/.github/workflows/module-auto-release.yml b/.github/workflows/module-auto-release.yml new file mode 100644 index 0000000..d823471 --- /dev/null +++ b/.github/workflows/module-auto-release.yml @@ -0,0 +1,40 @@ +name: Altis Module Auto Release On Manual Tags + +on: + push: + tags: + - '*.0.0' + - '*.0.0-beta*' + - '*.0.0-rc*' + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/github-script@v5 + with: + script: | + const tag = '${{ github.ref }}'.replace( 'refs/tags/', '' ); + const [ + _, + baseTag, + majorVersion, + stability, + preReleaseVersion, + ] = tag.match( /^((\d+)\.\d+\.\d+)(?:-(beta|rc)\.?(\d+)?)?/ ) + + let nameSuffix = ''; + if ( stability ) { + nameSuffix = stability === 'beta' ? 'Beta' : 'Release Candidate'; + nameSuffix = ' ' + nameSuffix + ' ' + preReleaseVersion; + } + + // Create new release from tag. + await github.request( `POST /repos/${{ github.repository }}/releases`, { + name: `${ baseTag }${ nameSuffix }`, + tag_name: tag, + target_commitish: `v${ majorVersion }-branch`, + generate_release_notes: true, + prerelease: !! stability, + } ); diff --git a/.github/workflows/module-auto-tagging.yml b/.github/workflows/module-auto-tagging.yml new file mode 100644 index 0000000..92ff827 --- /dev/null +++ b/.github/workflows/module-auto-tagging.yml @@ -0,0 +1,68 @@ +name: Altis Module Auto Tagging + +on: + push: + branches: + - v*-branch* + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2.4.1 + - 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, + } );