Debian Codegraph @

new/.github/workflows/release.yml

raw
1 name: Release Packages
2
3 on:
4 push:
5 branches:
6 - master
7
8 permissions:
9 # Jobs requiring OIDC (e.g., npm publish) must request `id-token: write` at the job level.
10 contents: read
11 pages: write
12
13 jobs:
14 publish:
15 # let's ignore release commits, otherwise it'll try to run twice
16 if: |
17 !startsWith(github.event.head_commit.message , 'chore(release):') &&
18 !startsWith(github.event.head_commit.message , 'chore(repo):')
19
20 permissions:
21 # Required for `versioner` to push release commits/tags and for npm OIDC publish.
22 contents: write
23 id-token: write
24
25 runs-on: ubuntu-latest
26
27 name: release
28
29 steps:
30 - name: Checkout Commit
31 uses: actions/checkout@v4
32 with:
33 fetch-depth: 2
34 token: ${{ secrets.GH_TOKEN }}
35
36 - name: Update Master
37 run: |
38 set -euo pipefail
39 DEFAULT_BRANCH="${{ github.event.repository.default_branch }}"
40 # Avoid implicit merges; update the remote-tracking ref explicitly
41 git fetch --no-tags --force origin "+refs/heads/${DEFAULT_BRANCH}:refs/remotes/origin/${DEFAULT_BRANCH}"
42 git checkout "${DEFAULT_BRANCH}"
43 git fetch --tags
44
45 - name: Setup Node
46 uses: actions/setup-node@v3
47 with:
48 node-version: 20
49 registry-url: https://registry.npmjs.org/
50
51 - name: Install PNPM
52 uses: pnpm/action-setup@v4
53
54 - name: ESLint Cache
55 uses: actions/cache@v3
56 with:
57 path: ./.eslintcache
58 key: ${{ runner.os }}-eslintcache-${{ hashFiles('./eslintcache') }}
59 restore-keys: |
60 ${{ runner.os }}-eslintcache-
61
62 - name: Sanity Check
63 run: |
64 echo git `git version`;
65 echo branch `git branch --show-current`;
66 echo node `node -v`;
67 echo pnpm `pnpm -v`
68 echo `moon --version`
69
70 - name: Initliaze .npmrc
71 run: >
72 echo -e "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}\n$(cat .npmrc)" > .npmrc
73 && cat -n .npmrc
74
75 - name: Set Git Config
76 run: |
77 git config pull.rebase false
78 git config --global user.email "[email protected]"
79 git config --global user.name "Release Workflow"
80 git remote set-url origin https://github.com/${{ github.repository }}
81
82 - name: pnpm install
83 run: pnpm install --frozen-lockfile
84
85 - name: Build Packages
86 run: pnpm --recursive build
87
88 - name: Lint Monorepo
89 run: pnpm lint
90
91 - name: Run Tests
92 run: pnpm --filter [HEAD^] test
93
94 - name: OIDC Preflight
95 shell: bash
96 run: |
97 if [ -z "${ACTIONS_ID_TOKEN_REQUEST_URL:-}" ] || [ -z "${ACTIONS_ID_TOKEN_REQUEST_TOKEN:-}" ]; then
98 echo "Missing GitHub Actions OIDC env vars (ACTIONS_ID_TOKEN_REQUEST_URL/TOKEN)." >&2
99 echo "Ensure the job requests permissions: id-token: write." >&2
100 exit 1
101 fi
102
103 echo "OIDC env vars detected."
104
105 - name: Release and Publish Packages
106 run: pnpm --filter [HEAD^] --workspace-concurrency=1 release
107 env:
108 NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
109 NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
110
111 - name: Push Release and Cleanup
112 run: |
113 set -euo pipefail
114 DEFAULT_BRANCH="${{ github.event.repository.default_branch }}"
115 pnpm lint:docs
116 git checkout .npmrc
117 git add . && git commit --amend --no-edit
118 git pull origin "${DEFAULT_BRANCH}" --no-edit
119 git rebase
120 git push origin HEAD:"${DEFAULT_BRANCH}"
121 git push origin HEAD:"${DEFAULT_BRANCH}" --tags