-
-
Notifications
You must be signed in to change notification settings - Fork 274
71 lines (65 loc) · 2.63 KB
/
release.yml
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
67
68
69
70
71
name: Release packages
on:
pull_request:
types: [closed, labeled]
# workflow_dispatch:
# inputs:
# packagePath:
# description: 'Package path'
# required: true
jobs:
release:
runs-on: ubuntu-latest
if: ${{ !github.event.pull_request || github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'released') }}
steps:
- name: Check out code
uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8.4.0
run_install: false
- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v3
env:
cache-name: casl-deps
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('./pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install dependencies
run: pnpm install
- name: Release
env:
GH_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.RELEASE_NPM_TOKEN }}
run: |
changed_paths=$(gh pr view --json files --jq '.files.[].path' "${{ github.event.pull_request.number }}" | cut -d / -f 1,2 | uniq)
changed_packages=$(echo "$changed_paths" | grep ./packages)
pnpm_options=''
for path in $changed_packages; do
pnpm_options="${pnpm_options} --filter ./${path}"
done
if [ "$pnpm_options" = "" ]; then
echo -e "No packages to release:\n ${changed_paths}" >> $GITHUB_STEP_SUMMARY
exit 0;
fi
echo "running: pnpm run -r $pnpm_options release" >> $GITHUB_STEP_SUMMARY
pnpm run -r $pnpm_options release
released_packages=()
for path in $changed_packages; do
package_name=$(grep '"name":' $path/package.json | cut -d : -f 2 | cut -d '"' -f 2)
package_version=$(grep '"version":' $path/package.json | cut -d : -f 2 | cut -d '"' -f 2)
released_packages[${#released_packages[@]}]="${package_name}@${package_version}"
done
if [ "${{github.event.pull_request.number}}" != "" ]; then
gh pr comment "${{ github.event.pull_request.number }}" --body "🚀 Released in ${released_packages[@]}"
fi
echo "🚀 Released in ${released_packages[@]}" >> $GITHUB_STEP_SUMMARY