-
Notifications
You must be signed in to change notification settings - Fork 0
165 lines (139 loc) · 5.11 KB
/
build.yml
File metadata and controls
165 lines (139 loc) · 5.11 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
name: Build and Release
on:
push:
branches:
- master
paths:
- '*.cc'
- '*.h'
- binding.gyp
- .github/workflows/build.yml
jobs:
build-windows:
runs-on: windows-latest
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup Visual Studio Environment
uses: egor-tensin/vs-shell@v2
- name: Compile Library
run: cl /O2 /std:c++17 /LD FileSystem.cc
- name: Test Node.js Module
run: npm i
- name: Zip Library
run: powershell Compress-Archive -Path FileSystem.dll,FileSystem.lib,FileSystem.h,fsdef.h -DestinationPath FileSystem-windows.zip
- name: Upload Library
uses: actions/upload-artifact@v4
with:
name: FileSystem-windows.zip
path: FileSystem-windows.zip
build-linux:
runs-on: ubuntu-latest
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Checkout Code
uses: actions/checkout@v4
- name: Compile Library
run: g++ -O2 -fPIC -shared -o FileSystem.so FileSystem.cc
- name: Test Node.js Module
run: npm i
- name: Zip Library
run: zip FileSystem-linux.zip FileSystem.so FileSystem.h fsdef.h
- name: Upload Library
uses: actions/upload-artifact@v4
with:
name: FileSystem-linux.zip
path: FileSystem-linux.zip
release:
permissions: write-all
needs: [build-windows, build-linux]
runs-on: ubuntu-latest
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Checkout Code
uses: actions/checkout@v4
- name: Get Version
run: |
VERSION=$(jq -r '.version' package.json)
echo "Version: $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Download Windows Library
uses: actions/download-artifact@v4
with:
name: FileSystem-windows.zip
- name: Download Linux Library
uses: actions/download-artifact@v4
with:
name: FileSystem-linux.zip
- name: Check if Release Exists
run: |
response=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ env.VERSION }})
echo "Response: $response"
if [[ $response == *"Not Found"* ]]; then
echo "release_exists=false" >> $GITHUB_ENV
else
echo "release_exists=true" >> $GITHUB_ENV
release_id=$(echo $response | jq -r '.id')
upload_url=$(echo $response | jq -r '.upload_url')
echo "RELEASE_ID=$release_id" >> $GITHUB_ENV
echo "UPLOAD_URL=$upload_url" >> $GITHUB_ENV
fi
shell: bash
- name: Remove Library Assets from Existing Release
if: env.release_exists == 'true'
run: |
assets_url=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/releases/${{ env.RELEASE_ID }} | jq -r '.assets_url')
assets=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" $assets_url)
for asset_id in $(echo $assets | jq -r '.[].id'); do
echo "Deleting asset with ID: $asset_id"
curl -s -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/releases/assets/$asset_id
done
- name: Create Release
id: create_release
if: env.release_exists == 'false'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.VERSION }}
release_name: ${{ env.VERSION }}
body: "Automated Release of Library Builds"
- name: Upload Windows Library
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.UPLOAD_URL || steps.create_release.outputs.upload_url }}
asset_path: FileSystem-windows.zip
asset_name: FileSystem-windows.zip
asset_content_type: application/zip
- name: Upload Linux Library
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.UPLOAD_URL || steps.create_release.outputs.upload_url }}
asset_path: FileSystem-linux.zip
asset_name: FileSystem-linux.zip
asset_content_type: application/zip
- name: Setup NPM Release
if: env.release_exists == 'false'
run: |
unzip -n FileSystem-linux.zip
unzip -n FileSystem-windows.zip
rm -rfd FileSystem-*.zip .github FileSystem.cc README.md
- name: Publish to NPM
if: env.release_exists == 'false'
uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_TOKEN }}