From 5a157e9f4e847eefe240761dfc324062eba9bcda Mon Sep 17 00:00:00 2001 From: javieri-empathy <68222542+javieri-empathy@users.noreply.github.com> Date: Mon, 17 May 2021 10:47:54 +0200 Subject: [PATCH] ci: make releases create a new PR instead of committing in main. (#11) ci: make releases create a new PR instead of committing in main. EX-3886 --- .github/workflows/prepare-release.yml | 15 ++++++++++----- .github/workflows/publish-release.yml | 9 ++++++--- scripts/prepare-release.js | 13 +++++++------ scripts/publish-release.js | 16 ++++++++++------ 4 files changed, 33 insertions(+), 20 deletions(-) diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml index 310bf22b9f..68415b4ba4 100644 --- a/.github/workflows/prepare-release.yml +++ b/.github/workflows/prepare-release.yml @@ -30,9 +30,14 @@ jobs: git config --local user.email "x@empathy.co" git config --local user.name "empathy/x" - name: Prepare the release - run: "npm run prepare-release:${{ github.event.inputs.kind }}" - - name: Push changes - uses: ad-m/github-push-action@master + run: npm run prepare-release:${{ github.event.inputs.kind }} + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 with: - github_token: ${{ secrets.SUPPORT_TOKEN }} - branch: ${{ github.ref }} + token: ${{ secrets.SUPPORT_TOKEN }} + commit-message: "chore(release): prepare ${{ github.event.inputs.kind }} release" + committer: Interface X + title: ${{ github.event.inputs.kind }} release + body: Release preparation + branch: release + delete-branch: true diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 85120adec6..0be90a8eec 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -1,8 +1,11 @@ name: Release a new version on: - workflow_dispatch: + pull_request: + types: [ closed ] + branches: [ main ] jobs: release: + if: github.event.pull_request.merged == true && github.head_ref == 'release' runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -29,8 +32,8 @@ jobs: env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - name: Publish the release - run: 'npm run publish-release' - - name: Push changes + run: npm run publish-release + - name: Push tags uses: ad-m/github-push-action@master with: github_token: ${{ secrets.SUPPORT_TOKEN }} diff --git a/scripts/prepare-release.js b/scripts/prepare-release.js index c5f592fd54..9cd8e4ba5c 100644 --- a/scripts/prepare-release.js +++ b/scripts/prepare-release.js @@ -1,9 +1,10 @@ const { exec } = require('./utils'); -const [releaseKind = 'stable'] = process.argv.slice(2); -const releaseKindArgument = releaseKind === 'alpha' ? '--conventional-prerelease' : '--conventional-graduate'; +execLernaVersion(); -[ - `lerna version --conventional-commits --no-git-tag-version --yes ${ releaseKindArgument }`, - `git commit -m "chore(release): prepare ${releaseKind} release" -a` -].forEach(exec); \ No newline at end of file +function execLernaVersion() { + const [releaseKind = 'stable'] = process.argv.slice(2); + const releaseKindArgument = + releaseKind === 'alpha' ? '--conventional-prerelease' : '--conventional-graduate'; + exec(`lerna version --conventional-commits --no-git-tag-version --yes ${releaseKindArgument}`); +} diff --git a/scripts/publish-release.js b/scripts/publish-release.js index ccccef0cce..6c18fbf213 100644 --- a/scripts/publish-release.js +++ b/scripts/publish-release.js @@ -1,8 +1,12 @@ const { exec } = require('./utils'); -const changedPackages = JSON.parse(exec('lerna changed --json')); -exec(`lerna publish from-package --yes`); -changedPackages.forEach(changed => { - const tag = `${ changed.name }@${ changed.version }`; - exec(`git tag -a ${tag} -m "${tag}"`); -}); +addVersionTagForChangedPackages(); + +function addVersionTagForChangedPackages() { + const changedPackages = JSON.parse(exec('lerna changed --json')); + exec(`lerna publish from-package --yes`); + changedPackages.forEach(changed => { + const tag = `${changed.name}@${changed.version}`; + exec(`git tag -a ${tag} -m "${tag}"`); + }); +}