From 3c6bb07f5dcb1e5bee422e607f4c48ceb56827c0 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Wed, 15 May 2024 21:47:52 +0400 Subject: [PATCH 1/2] feat(.github): introduce updated release strategy --- .github/workflows/npm-publish-ci.yml | 27 ------------- .github/workflows/release-commit.yml | 50 ++++++++++++++++++++++++ .github/workflows/release-publish.yml | 56 +++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 27 deletions(-) delete mode 100644 .github/workflows/npm-publish-ci.yml create mode 100644 .github/workflows/release-commit.yml create mode 100644 .github/workflows/release-publish.yml diff --git a/.github/workflows/npm-publish-ci.yml b/.github/workflows/npm-publish-ci.yml deleted file mode 100644 index 704acc6..0000000 --- a/.github/workflows/npm-publish-ci.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: NPM Publish -on: - release: - types: [created] -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 18 - - run: npm ci - - run: npm test - publish-npm: - needs: build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 18 - registry-url: https://registry.npmjs.org/ - - run: npm ci - - run: npm publish - env: - NODE_AUTH_TOKEN: ${{secrets.npm_token}} diff --git a/.github/workflows/release-commit.yml b/.github/workflows/release-commit.yml new file mode 100644 index 0000000..2ce23d9 --- /dev/null +++ b/.github/workflows/release-commit.yml @@ -0,0 +1,50 @@ +name: Release commit +on: + release: + types: [published] +jobs: + + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 18 + + - name: Install dependencies + run: npm ci + + - name: Run unit tests + run: npm test + + create-release-commit: + needs: build + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: main + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 18 + registry-url: https://registry.npmjs.org/ + + - name: Install dependencies + run: npm ci + + - name: Initalize git user email + run: git config --global user.email "${{vars.RELEASE_USER_EMAIL}}" + - name: Initalize git user name + run: git config --global user.name "Release commit workflow" + + - name: Init release commit + run: npm run release -- --ci ${{github.event.release.tag_name}} + env: + GITHUB_TOKEN: ${{secrets.github_token}} diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml new file mode 100644 index 0000000..c4848dd --- /dev/null +++ b/.github/workflows/release-publish.yml @@ -0,0 +1,56 @@ +name: Release publish NPM +on: + push: + branches: + - release +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 18 + - run: npm ci + - run: npm test + publish-npm: + needs: build + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: main + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 18 + registry-url: https://registry.npmjs.org/ + + - name: Install dependencies + run: npm ci + - name: Initalize git user email + run: git config --global user.email "${{env.RELEASE_USER_EMAIL}}" + - name: Initalize git user name + run: git config --global user.name "Release publish workflow" + + - name: Initialize npm config + run: npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN + env: + NPM_TOKEN: ${{secrets.NPM_TOKEN}} + - name: Check if release is a pre-release + id: check_pre_release + run: echo "{name}=${{github.event.release.prerelease}}" >> $GITHUB_OUTPUT + + - name: Publish to npm + if: steps.check_pre_release.outputs.is_pre_release == 'true' + run: npm publish --tag beta + env: + GITHUB_TOKEN: ${{secrets.github_token}} + NODE_AUTH_TOKEN: ${{secrets.npm_token}} + - name: Publish to npm + if: steps.check_pre_release.outputs.is_pre_release != 'true' + run: npm publish + env: + GITHUB_TOKEN: ${{secrets.github_token}} + NODE_AUTH_TOKEN: ${{secrets.npm_token}} From 98fa5f154fc9c9efe5e01fe720d3a921ba5d6d64 Mon Sep 17 00:00:00 2001 From: Narek Hovhannisyan Date: Fri, 17 May 2024 23:34:51 +0400 Subject: [PATCH 2/2] fix(.github): update release commit workflow to open PR --- .github/workflows/release-commit.yml | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release-commit.yml b/.github/workflows/release-commit.yml index 2ce23d9..8689820 100644 --- a/.github/workflows/release-commit.yml +++ b/.github/workflows/release-commit.yml @@ -2,8 +2,11 @@ name: Release commit on: release: types: [published] -jobs: +env: + PR_BRANCH_NAME: release-${{github.event.release.tag_name}} + +jobs: build: runs-on: ubuntu-latest steps: @@ -28,7 +31,7 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - ref: main + ref: ${{ github.event.repository.default_branch }} - name: Setup Node.js uses: actions/setup-node@v4 @@ -41,10 +44,24 @@ jobs: - name: Initalize git user email run: git config --global user.email "${{vars.RELEASE_USER_EMAIL}}" + - name: Initalize git user name run: git config --global user.name "Release commit workflow" - - name: Init release commit - run: npm run release -- --ci ${{github.event.release.tag_name}} + - name: Create release branch + run: | + git checkout -b $PR_BRANCH_NAME + git push --set-upstream origin $PR_BRANCH_NAME + echo "branch=$PR_BRANCH_NAME" >> $GITHUB_ENV + + - name: Bump version and push changes using release-it + run: | + npm run release -- --ci ${{github.event.release.tag_name}} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Create pull request + run: gh pr create -B ${{ github.event.repository.default_branch }} -H $PR_BRANCH_NAME --title "Release ${{github.event.release.tag_name}}" --body "${{github.event.release.body}}" env: - GITHUB_TOKEN: ${{secrets.github_token}} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + \ No newline at end of file