-
Notifications
You must be signed in to change notification settings - Fork 4
80 lines (66 loc) · 2.33 KB
/
publish-to-npm.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
name: Publish to NPM
on:
push:
branches:
- master
jobs:
publish:
name: Publish @kubejs/${{ matrix.package_name }}
runs-on: ubuntu-latest
strategy:
matrix:
package_name: [ "plugin", "generator" ]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
with:
node-version: 20
registry-url: 'https://registry.npmjs.org'
- name: Restore hash from cache
id: restore-cache
uses: actions/cache@v2
with:
path: .folder_hash
key: :::app-hash:@kubejs/${{ matrix.package_name }}
- name: Calculate folder hash
id: calculate-hash
run: |
FOLDER_TO_HASH="kube-js/${{ matrix.package_name }}"
HASH_FILE=".folder_hash"
# Calculate the current hash
CURRENT_HASH=$(find "$FOLDER_TO_HASH" -type f -exec sha256sum {} \; | sort -k 2 | sha256sum | awk '{ print $1 }')
echo "Current hash: $CURRENT_HASH"
# Load the saved hash
if [[ -f $HASH_FILE ]]; then
SAVED_HASH=$(cat $HASH_FILE)
else
SAVED_HASH=null
fi
echo "Saved hash: $SAVED_HASH"
# Compare hashes
if [[ "$CURRENT_HASH" != "$SAVED_HASH" ]]; then
echo "Folder has changed."
echo "changed=true" >> $GITHUB_OUTPUT
echo "$CURRENT_HASH" > $HASH_FILE
else
echo "Folder has not changed."
echo "changed=false" >> $GITHUB_OUTPUT
fi
- run: corepack enable
if: steps.calculate-hash.outputs.changed == 'true'
- run: yarn
if: steps.calculate-hash.outputs.changed == 'true'
- run: yarn workspace @kubejs/${{ matrix.package_name }} build
if: steps.calculate-hash.outputs.changed == 'true'
- run: yarn workspace @kubejs/${{ matrix.package_name }} publish:me
if: steps.calculate-hash.outputs.changed == 'true'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Save updated hash to cache
if: steps.calculate-hash.outputs.changed == 'true'
uses: actions/cache@v2
with:
path: .folder_hash
key: :::app-hash:@kubejs/${{ matrix.package_name }}