|
| 1 | +name: Release |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + inputs: |
| 5 | + strategy: |
| 6 | + description: Valid semver number <x.x.x> or strategy <patch, minor, major> |
| 7 | + default: "patch" |
| 8 | + required: false |
| 9 | + |
| 10 | +jobs: |
| 11 | + release: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + strategy: |
| 15 | + matrix: |
| 16 | + node-version: [18.x] |
| 17 | + |
| 18 | + if: ${{ github.actor == 'pebie' || github.actor == 'Crow-EH' || github.actor == 'fthouraud' || github.actor == 'leguellec' || github.actor == 'rande' }} |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@v3 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + |
| 26 | + - name: Get yarn cache directory path |
| 27 | + id: yarn-cache-dir-path |
| 28 | + run: echo "::set-output name=dir::$(yarn config get cacheFolder)" |
| 29 | + |
| 30 | + - uses: actions/cache@v3 |
| 31 | + id: yarn-cache |
| 32 | + with: |
| 33 | + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} |
| 34 | + key: ${{ runner.os }}-yarn-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }} |
| 35 | + restore-keys: ${{ runner.os }}-yarn- |
| 36 | + |
| 37 | + - name: Install dependencies |
| 38 | + if: steps.yarn-cache-dir-path.outputs.cache-hit != 'true' |
| 39 | + run: yarn install |
| 40 | + |
| 41 | + - name: Build |
| 42 | + run: yarn build |
| 43 | + |
| 44 | + - name: Bump the version using input strategy |
| 45 | + run: | |
| 46 | + git config user.name github-actions[bot] |
| 47 | + git config user.email 41898282+github-actions[bot]@users.noreply.github.com |
| 48 | + yarn version --new-version ${{ github.event.inputs.strategy }} --no-git-tag-version |
| 49 | +
|
| 50 | + - name: Update changelog |
| 51 | + id: changelog |
| 52 | + run: | |
| 53 | + CHANGELOG=$(yarn conventional-changelog -p conventionalcommits -r -u 0) |
| 54 | + echo -e "${CHANGELOG}\n\n\n\n$(cat CHANGELOG.md)" > CHANGELOG.md |
| 55 | + BODY=$(echo -e "${CHANGELOG}" | sed -e "1,2d") |
| 56 | + BODY="${BODY//'%'/'%25'}" |
| 57 | + BODY="${BODY//$'\n'/'%0A'}" |
| 58 | + BODY="${BODY//$'\r'/'%0D'}" |
| 59 | + echo "::set-output name=body::${BODY}" |
| 60 | +
|
| 61 | + - name: Log changes |
| 62 | + run: | |
| 63 | + echo "The changelog will be : ${{ steps.changelog.outputs.body }}" |
| 64 | + |
| 65 | + - name: Get version |
| 66 | + id: package-version |
| 67 | + uses: martinbeentjes/npm-get-version-action@v1.2.3 |
| 68 | + |
| 69 | + - name: Create tag |
| 70 | + run: | |
| 71 | + git config user.name github-actions[bot] |
| 72 | + git config user.email 41898282+github-actions[bot]@users.noreply.github.com |
| 73 | + git add . |
| 74 | + git commit -m "chore(bump): release v${{ steps.package-version.outputs.current-version }}" |
| 75 | + git push |
| 76 | + git tag -a v${{ steps.package-version.outputs.current-version }} -m "chore(tag): release v${{ steps.package-version.outputs.current-version }}" |
| 77 | + git push origin v${{ steps.package-version.outputs.current-version }} |
| 78 | +
|
| 79 | + - name: Create release |
| 80 | + uses: softprops/action-gh-release@v1 |
| 81 | + with: |
| 82 | + body: ${{ steps.changelog.outputs.body }} |
| 83 | + tag_name: v${{ steps.package-version.outputs.current-version }} |
| 84 | + name: v${{ steps.package-version.outputs.current-version }} |
| 85 | + |
| 86 | + - name: Setup npmrc |
| 87 | + uses: actions/setup-node@v3 |
| 88 | + with: |
| 89 | + node-version: '16.x' |
| 90 | + registry-url: 'https://registry.npmjs.org' |
| 91 | + |
| 92 | + - name: Publish to NPM |
| 93 | + run: npm publish --access public |
| 94 | + env: |
| 95 | + VERSION: ${{ steps.package-version.outputs.current-version }} |
| 96 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments