-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (81 loc) · 2.58 KB
/
snapshot.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: Release snapshot
on:
workflow_dispatch:
inputs:
ref:
type: string
required: false
default: ''
workflow_call:
inputs:
ref:
type: string
required: false
default: ''
outputs:
publishedPackages:
value: ${{ jobs.release.outputs.publishedPackages }}
numberOfPackages:
value: ${{ jobs.release.outputs.numberOfPackages }}
jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
outputs:
publishedPackages: ${{ steps.package_list.outputs.LIST }}
numberOfPackages: ${{ steps.packages_number.outputs.NUMBER_OF_PACKAGES }}
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}
- name: Get SHA
id: get_sha
run: echo "SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Setup Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
registry-url: 'https://npm.pkg.github.com'
- name: Install Dependencies
run: yarn
- name: Snapshot
run: yarn changeset version --snapshot $REF
env:
REF: ${{ steps.get_sha.outputs.SHA }}
- name: Collect the number of packages
id: packages_number
run: |
echo "NUMBER_OF_PACKAGES=$(git ls-files --modified | grep package.json | wc -l)" >> $GITHUB_OUTPUT
- name: Collect all the packages
id: package_list
run: |
listChangedPackages () {
for filename in `git ls-files --modified | grep package.json`; do
cat "$filename" | jq -r '.name + "@" + .version'
done
}
if [[ "$NUMBER_OF_PACKAGES" -eq "0" ]]; then
echo "LIST=" >> $GITHUB_OUTPUT
else
echo 'LIST<<EOF' >> $GITHUB_OUTPUT
listChangedPackages | grep $SHA >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
fi
env:
SHA: ${{ steps.get_sha.outputs.SHA }}
NUMBER_OF_PACKAGES: ${{ steps.packages_number.outputs.NUMBER_OF_PACKAGES }}
- name: Publish the snapshot
run: |
yarn changeset publish --tag alpha --no-git-tag --snapshot
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Output
if: steps.packages_number.outputs.NUMBER_OF_PACKAGES > 0
run: |
echo "$LIST" | awk '{print " - `" $0 "`"}' >> $GITHUB_STEP_SUMMARY
env:
LIST: ${{ steps.package_list.outputs.LIST }}