-
Notifications
You must be signed in to change notification settings - Fork 0
193 lines (183 loc) · 6.38 KB
/
build.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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
name: CI
on:
pull_request:
branches:
- master
push:
branches:
- master
- issue/*
# - dev/harai
env:
AWS_ACCOUNT_ID: '013230744746'
TEST_ACCESS_KEY_ID: AKIAQGFE5ESVOSITRJJK
TEST_S3_SRC_BUCKET: gutenberg-ext-imgconv-tests3srcbucket-1nfmay8h6zit1
TEST_S3_DEST_BUCKET: gutenberg-ext-imgconv-tests3destbucket-a6ao4v2r6ks5
TEST_S3_ANOTHER_SRC_BUCKET: gutenberg-ext-imgconv-tests3anothersrcbucket-1lj3632c3dn19
TEST_S3_ANOTHER_DEST_BUCKET: gutenberg-ext-imgconv-tests3anotherdestbucket-1xrab2bhory0u
RELEASE_ACCESS_KEY_ID: AKIAQGFE5ESVD2ODKAC5
REPO_BUCKET: gutenberg-ext-imgconv-repobucket-1bxd9jnafv4c5
GO_VERSION: 1.21.3
jobs:
build-go:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@main
- uses: actions/setup-go@main
with:
go-version: '~${{env.GO_VERSION}}'
- run: echo "$TEST_ACCESS_KEY_ID" > config/test/access-key-id
- run: echo "$AWS_ACCOUNT_ID" > config/test/aws-account-id
- run: echo "$TEST_S3_SRC_BUCKET" > config/test/s3-src-bucket
- run: echo "$TEST_S3_DEST_BUCKET" > config/test/s3-dest-bucket
- run: echo "$TEST_S3_ANOTHER_SRC_BUCKET" > config/test/s3-another-src-bucket
- run: echo "$TEST_S3_ANOTHER_DEST_BUCKET" > config/test/s3-another-dest-bucket
- run: echo "$TEST_SECRET_ACCESS_KEY" > config/test/secret-access-key
env:
TEST_SECRET_ACCESS_KEY: ${{secrets.AWS_TEST_SECRET_ACCESS_KEY}}
- run: sudo apt-get install -y gcc
- name: Generate build number
uses: onyxmueller/build-tag-number@main
with:
token: ${{secrets.GITHUB_TOKEN}}
prefix: build_number_generator
- name: Print new build number
run: echo "Build number is $BUILD_NUMBER"
- name: Save the build number
run: echo "$BUILD_NUMBER" > work/BUILD_NUMBER
- name: Embed build number into code
run: echo "build-$BUILD_NUMBER" > ./VERSION
- name: Build on the same machine image as AWS Lambda
# Add "safe.directory" to avoid "detected dubious ownership in repository" error.
run: |
cmd="$(
cat <<EOF
yum install -y git gcc tar binutils
cd /
curl -fsSL -o go.tar.gz https://go.dev/dl/go${{env.GO_VERSION}}.linux-amd64.tar.gz
tar -C /usr/local -xzf go.tar.gz
ln -s /usr/local/go/bin/go /usr/local/bin/go
cd /workspace
git config --global --add safe.directory /workspace
GOOS=linux GOARCH=amd64 go build \
-ldflags "-X github.com/tarosky/gutenberg-imgconv/imgconv.Version=$(< ./VERSION)" \
-tags lambda.norpc \
-o work/bootstrap \
lambda/lambda.go
EOF
)"
docker container run \
--rm \
--entrypoint /bin/bash \
--mount type=bind,source="$(pwd)",target=/workspace \
amazonlinux:2 \
-eux -c "$cmd"
- uses: actions/upload-artifact@main
with:
name: artifact-bootstrap
path: work/bootstrap
- uses: actions/upload-artifact@main
with:
name: build-number
path: work/BUILD_NUMBER
build-uglifyjs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@main
- run: uglifyjs/build-image
- run: uglifyjs/run-nexe
- uses: actions/upload-artifact@main
with:
name: artifact-uglifyjs
path: work/uglifyjs
test:
needs: build-uglifyjs
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@main
- uses: actions/download-artifact@main
with:
name: artifact-bootstrap
path: work
- uses: actions/download-artifact@main
with:
name: artifact-uglifyjs
path: work
- run: chmod +x work/uglifyjs
- uses: actions/setup-go@main
with:
go-version: '~${{env.GO_VERSION}}'
- run: echo "$TEST_ACCESS_KEY_ID" > config/test/access-key-id
- run: echo "$AWS_ACCOUNT_ID" > config/test/aws-account-id
- run: echo "$TEST_S3_SRC_BUCKET" > config/test/s3-src-bucket
- run: echo "$TEST_S3_DEST_BUCKET" > config/test/s3-dest-bucket
- run: echo "$TEST_S3_ANOTHER_SRC_BUCKET" > config/test/s3-another-src-bucket
- run: echo "$TEST_S3_ANOTHER_DEST_BUCKET" > config/test/s3-another-dest-bucket
- run: echo "$TEST_SECRET_ACCESS_KEY" > config/test/secret-access-key
env:
TEST_SECRET_ACCESS_KEY: ${{secrets.AWS_TEST_SECRET_ACCESS_KEY}}
- run: go get github.com/jstemmer/go-junit-report
- run: go install github.com/jstemmer/go-junit-report
- run: go test -v ./bootstrap 2>&1 | tee work/test.log
- run: go-junit-report < work/test.log > work/report.xml
- uses: actions/upload-artifact@main
with:
name: report.xml
path: work/report.xml
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@master
if: always()
with:
github_token: ${{secrets.GITHUB_TOKEN}}
files: work/report.xml
bundle:
needs:
- build-go
- build-uglifyjs
runs-on: ubuntu-20.04
steps:
- uses: actions/download-artifact@main
with:
name: artifact-bootstrap
- uses: actions/download-artifact@main
with:
name: artifact-uglifyjs
- run: chmod +x bootstrap uglifyjs
- run: zip -j imgconv.zip ./bootstrap ./uglifyjs
- uses: actions/upload-artifact@main
with:
name: artifact-imgconv
path: imgconv.zip
release:
needs:
- bundle
- test
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-20.04
steps:
- uses: actions/download-artifact@main
with:
name: artifact-imgconv
- uses: actions/download-artifact@main
with:
name: build-number
- name: set BUILD_NUMBER
run: echo "BUILD_NUMBER=$(< ./BUILD_NUMBER)" >> $GITHUB_ENV
- name: set ASSET_NAME
run: echo "ASSET_NAME=imgconv.build-$BUILD_NUMBER-awslambda-provided-amd64.zip" >> $GITHUB_ENV
- name: rename
run: cp imgconv.zip "$ASSET_NAME"
- id: create_release
uses: softprops/action-gh-release@master
with:
tag_name: build-${{env.BUILD_NUMBER}}
name: Build ${{env.BUILD_NUMBER}}
draft: false
prerelease: false
files: ${{env.ASSET_NAME}}
- uses: aws-actions/configure-aws-credentials@main
with:
aws-access-key-id: ${{env.RELEASE_ACCESS_KEY_ID}}
aws-secret-access-key: ${{secrets.AWS_RELEASE_SECRET_ACCESS_KEY}}
aws-region: ap-northeast-1
- run: aws s3 cp imgconv.zip "s3://$REPO_BUCKET/$ASSET_NAME"