ci(release): 4.0.0 (#984) #751
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release to NPM | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
Release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
- name: Get yarn cache directory path | |
id: yarn-cache-dir-path | |
run: echo "::set-output name=dir::$(yarn cache dir)" | |
- uses: actions/cache@v3 | |
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) | |
with: | |
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Install dependencies | |
run: yarn install --frozen-lock-file --prefer-offline | |
- name: Get version from package.json before release step | |
id: initversion | |
run: echo "::set-output name=version::$(npm run get-version --silent)" | |
- name: Build NPM package | |
run: yarn build | |
- name: Release to NPM | |
id: release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
GIT_AUTHOR_NAME: duffel-bot | |
GIT_AUTHOR_EMAIL: duffel-bot-read-write@duffel.com | |
GIT_COMMITTER_NAME: duffel-bot | |
GIT_COMMITTER_EMAIL: duffel-bot-read-write@duffel.com | |
run: yarn release | |
- name: Get version from package.json after release step | |
id: extractver | |
run: echo "::set-output name=extractver::$(npm run get-version --silent)" | |
- name: Check if package versions are different | |
run: | | |
echo "Init Version - ${{ steps.initversion.outputs.version }}" | |
echo "extract version - ${{ steps.extractver.outputs.extractver }}" | |
echo "extract version - ${{ steps.initversion.outputs.version != steps.extractver.outputs.extractver }}" | |
- name: Create Pull Request with updated package files | |
id: cpr | |
if: steps.initversion.outputs.version != steps.extractver.outputs.extractver | |
uses: peter-evans/create-pull-request@v5.0.3 | |
with: | |
token: ${{ secrets.PAT }} | |
commit-message: 'ci(release): ${{ steps.extractver.outputs.extractver }}' | |
committer: duffel-bot <duffel-bot-read-write@duffel.com> | |
author: duffel-bot <duffel-bot-read-write@duffel.com> | |
title: 'ci(release): ${{ steps.extractver.outputs.extractver }}' | |
body: 'Version bump in package.json and package-lock.json for release [${{ steps.extractver.outputs.extractver }}](https://github.com/${{github.repository}}/releases/tag/v${{ steps.extractver.outputs.extractver }})' | |
branch: version-bump/${{ steps.extractver.outputs.extractver }} | |
labels: | | |
automated pr | |
- name: Check outputs | |
run: | | |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" | |
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" | |
- name: Enable Pull Request Automerge | |
if: steps.cpr.outputs.pull-request-operation == 'created' | |
uses: peter-evans/enable-pull-request-automerge@v3 | |
with: | |
token: ${{ secrets.PAT }} | |
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }} | |
merge-method: squash |