-
Notifications
You must be signed in to change notification settings - Fork 6
135 lines (128 loc) · 4.03 KB
/
ci.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
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
name: Build and Test
on:
push:
branches:
- '**'
pull_request:
branches:
- main
workflow_dispatch: {}
jobs:
build_and_test:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: '20'
cache: npm
cache-dependency-path: |
backend/package-lock.json
frontend/package-lock.json
e2e/package-lock.json
- name: Build and Test
run: PARALLEL_BUILD=false PARALLEL_E2E=false EXPLICIT_WAIT_TIMEOUT=20000 TEST_TIMEOUT=60000 npm test
- name: Bundle
run: |
cd build
rm -r node_modules
tar -czf ../build.tar.gz .
- name: Upload Bundle
uses: actions/upload-artifact@v4
with:
name: refacto
retention-days: 1
if-no-files-found: error
path: build.tar.gz
smoke_test:
needs:
- build_and_test
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
include:
- { node: '18' }
- { node: '20' }
- { node: '22' }
steps:
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Download Bundle
uses: actions/download-artifact@v4
with:
name: refacto
- name: Unpack
run: tar -xf build.tar.gz && rm build.tar.gz
- name: Smoke Test
run: |
set -e;
npm install --omit=dev;
./index.js > output.log 2>&1 & APP_PID="$!";
while [ ! -f output.log ] || ! grep 'Available at' < output.log > /dev/null 2>&1; do
if ! ps -p "$APP_PID" > /dev/null; then
APP_EXIT_CODE="$(wait "$APP_PID" > /dev/null; echo "$?")";
cat output.log;
echo "Application failed to launch (exit code: $APP_EXIT_CODE).";
false;
fi;
sleep 0.1;
done;
wget localhost:5000 -O test-index.html;
if ! grep '<title>Refacto</title>' < test-index.html > /dev/null; then
cat output.log;
echo "Unexpected main page response" >&2;
cat test-index.html;
false;
fi;
kill -2 "$APP_PID";
wait "$APP_PID";
if ! grep 'Shutdown complete' < output.log > /dev/null; then
cat output.log;
echo "Application failed to shut down" >&2;
false;
fi;
create_release:
needs:
- smoke_test
runs-on: ubuntu-latest
timeout-minutes: 10
if: ${{ github.ref == 'refs/heads/main' && github.head_ref == null }}
permissions:
contents: write
steps:
- name: Download Bundle
uses: actions/download-artifact@v4
with:
name: refacto
- name: Create Release
env:
API_BASE: 'https://api.github.com/repos/${{ github.repository }}'
COMMIT: ${{ github.sha }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e;
NAME="$(date -u '+%Y%m%d-%H%M%S')";
echo "Creating release $NAME...";
wget -S \
--header='Accept: application/vnd.github.v3+json' \
--header="Authorization: token $GITHUB_TOKEN" \
--post-data="$(jq -n --arg n "$NAME" --arg c "$COMMIT" '{tag_name: $n, target_commitish: $c}')" \
"$API_BASE/releases" -O release.json;
cat release.json;
echo "Uploading bundle...";
UPLOAD_URL="$(jq -r '.upload_url' < release.json | sed 's/{[^}]*}//')";
wget -S \
--header='Accept: application/vnd.github.v3+json' \
--header="Authorization: token $GITHUB_TOKEN" \
--header='Content-Type: application/gzip' \
--post-file='build.tar.gz' \
"$UPLOAD_URL?name=build.tar.gz" -O release-file.json;
cat release-file.json;
echo "Done.";