1
+ name : Build lambda layer for sharp
2
+
3
+ on :
4
+ push :
5
+ branches :
6
+ - master
7
+ pull_request :
8
+ branches :
9
+ - master
10
+ schedule :
11
+ - cron : ' 0 4 * * *'
12
+ workflow_dispatch :
13
+
14
+ jobs :
15
+ build :
16
+ runs-on : ubuntu-latest
17
+ permissions :
18
+ contents : write
19
+ steps :
20
+ - name : Setup node
21
+ uses : actions/setup-node@v4
22
+ with :
23
+ node-version : ' ^20.10.0'
24
+ - name : Checkout
25
+ uses : actions/checkout@v3
26
+ - name : Install esbuild
27
+
28
+
29
+ - name : Install sharp - arm64
30
+ run : npm i --save-exact --os=linux --cpu=arm64 --libc=glibc sharp
31
+ - name : Remove musl-based binary # @npm/cli#6914
32
+ run : rm -rf node_modules/@img/*-linuxmusl*
33
+ - name : Get sharp version
34
+ id : version
35
+ uses : notiz-dev/github-action-json-property@release
36
+ with :
37
+ path : ' package.json'
38
+ prop_path : ' dependencies.sharp'
39
+ - name : esbuild - arm64
40
+ run : esbuild --bundle ./node_modules/sharp/ --outfile=index.js --minify --format=cjs --platform=node
41
+ - name : Zip - arm64
42
+ run : |
43
+ mkdir -p nodejs/node_modules/sharp/lib
44
+ mv index.js nodejs/node_modules/sharp/lib/
45
+ mv node_modules/sharp/package.json nodejs/node_modules/sharp/
46
+ mv node_modules/sharp/LICENSE nodejs/node_modules/sharp/
47
+ mv node_modules/sharp/lib/index.d.ts nodejs/node_modules/sharp/lib/
48
+ mv node_modules/@img nodejs/node_modules/
49
+ zip -r release-arm64 nodejs
50
+ - name : Clean arm64
51
+ run : rm -rf nodejs node_modules # keep package.json for keeping the version
52
+
53
+ - name : Install sharp - x64
54
+ run : npm i --save-exact --os=linux --cpu=x64 --libc=glibc sharp
55
+ - name : Remove musl-based binary # @npm/cli#6914
56
+ run : rm -rf node_modules/@img/*-linuxmusl*
57
+ - name : esbuild - x64
58
+ run : esbuild --bundle ./node_modules/sharp/ --outfile=index.js --minify --format=cjs --platform=node
59
+ - name : Zip - x64
60
+ run : |
61
+ mkdir -p nodejs/node_modules/sharp/lib
62
+ mv index.js nodejs/node_modules/sharp/lib/
63
+ mv node_modules/sharp/package.json nodejs/node_modules/sharp/
64
+ mv node_modules/sharp/LICENSE nodejs/node_modules/sharp/
65
+ mv node_modules/sharp/lib/index.d.ts nodejs/node_modules/sharp/lib/
66
+ mv node_modules/@img nodejs/node_modules/
67
+ zip -r release-x64 nodejs
68
+ - name : Clean x64
69
+ run : rm -rf nodejs node_modules # keep package.json for keeping the version
70
+
71
+ - name : Install sharp - all
72
+ run : |
73
+ npm i --os=linux --cpu=x64 --libc=glibc sharp
74
+ npm i --os=linux --cpu=arm64 --libc=glibc sharp
75
+ - name : Remove musl-based binary # @npm/cli#6914
76
+ run : rm -rf node_modules/@img/*-linuxmusl*
77
+ - name : esbuild - all
78
+ run : esbuild --bundle ./node_modules/sharp/ --outfile=index.js --minify --format=cjs --platform=node
79
+ - name : Zip - all
80
+ run : |
81
+ mkdir -p nodejs/node_modules/sharp/lib
82
+ mv index.js nodejs/node_modules/sharp/lib/
83
+ mv node_modules/sharp/package.json nodejs/node_modules/sharp/
84
+ mv node_modules/sharp/LICENSE nodejs/node_modules/sharp/
85
+ mv node_modules/sharp/lib/index.d.ts nodejs/node_modules/sharp/lib/
86
+ mv node_modules/@img nodejs/node_modules/
87
+ zip -r release-all nodejs
88
+
89
+ - name : Test
90
+ run : |
91
+ cp test.mjs nodejs/test.mjs
92
+ node nodejs/test.mjs
93
+ if [ ! -f test.png ]; then exit 1 ; fi
94
+
95
+ - name : Current version
96
+ id : version_current
97
+ run : echo "sharpver=$(cat PREVIOUS_VERSION.txt)" >> $GITHUB_ENV
98
+ - name : Update PREVIOUS_VERSION.txt
99
+ if : ${{ env.sharpver != steps.version.outputs.prop && github.event_name != 'pull_request' }}
100
+ run : echo ${{steps.version.outputs.prop}} > PREVIOUS_VERSION.txt
101
+ - name : Create commit
102
+ uses : stefanzweifel/git-auto-commit-action@v4
103
+ if : ${{ env.sharpver != steps.version.outputs.prop && github.event_name != 'pull_request' }}
104
+ with :
105
+ commit_message : ${{steps.version.outputs.prop}}
106
+ file_pattern : PREVIOUS_VERSION.txt
107
+ - name : Create release
108
+ uses : softprops/action-gh-release@v1
109
+ if : ${{ env.sharpver != steps.version.outputs.prop && github.event_name != 'pull_request' }}
110
+ with :
111
+ files : " release*"
112
+ body : ${{steps.version.outputs.prop}}
113
+ tag_name : ${{steps.version.outputs.prop}}
0 commit comments