aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/publish-release.yml
blob: ac3839acf962d2ac0a42c43379f858dd5dedf2dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
name: Publish Release

on:
  release:
    types: [published]

permissions:
  # we use a personal access token to push the release branch
  id-token: write # required for provenance/signed releases on npm

jobs:
  publish:
    name: Publish Release
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
        with:
          fetch-depth: 0 # we want to push the release branch later
          token: ${{ secrets.GH_TOKEN }}

      - name: Install pnpm
        uses: pnpm/action-setup@a7487c7e89a18df4991f7f222e4898a00d66ddda # v4.1.0

      - name: Set node version to 24
        uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
        with:
          node-version: 24.6.0
          cache: 'pnpm'

      - name: Install deps
        run: pnpm install --frozen-lockfile

      - name: Gather release information
        run: |
          RELEASE_VERSION=$(jq -r '.version' package.json)
          echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
          RELEASE_MAJOR=$(jq -r '.version | split(".")[0]' package.json)
          echo "RELEASE_MAJOR=$RELEASE_MAJOR" >> $GITHUB_ENV
          DIST_TAG=$(jq -r '.version | if split("-")[1] == null then "latest" else "next" end' package.json)
          echo "DIST_TAG=$DIST_TAG" >> $GITHUB_ENV

      - name: Prepare README
        run: |
          echo -e "$(grep -P '## 📙 API Documentation' -B 10000 README.md)\n\n- [Getting Started Guide](https://fakerjs.dev/guide/)\n- [API Reference](https://fakerjs.dev/api/)\n\n$(grep -P '## 🚀 Features' -A 10000 README.md)" > README.md
          sed -i "s|/fakerjs.dev/|/v$RELEASE_MAJOR.fakerjs.dev/|g" README.md

      - name: Set publishing config
        run: pnpm config set '//registry.npmjs.org/:_authToken' "${NPM_AUTH_TOKEN}"
        env:
          NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

      - name: Publish
        run: |
          pnpm publish --tag next --no-git-checks
        env:
          NPM_CONFIG_PROVENANCE: true

      - name: Set latest/next dist-tag
        run: |
          pnpm dist-tag add @faker-js/faker@$RELEASE_VERSION $DIST_TAG

      - name: Push to Release Branch
        run: |
          git push origin $GITHUB_REF_NAME:v$RELEASE_MAJOR