-
Notifications
You must be signed in to change notification settings - Fork 2
162 lines (136 loc) · 4.84 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
on: push
name: Build
jobs:
build:
name: Build
runs-on: ubuntu-latest
env:
CI: true
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: ".tool-versions"
cache: 'npm'
- name: Setup dependencies
run: npm ci
- name: Run Tests
run: npm run test
release:
name: Release
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
outputs:
release_created: ${{ steps.release-please.outputs.release_created }}
release_tag: ${{ steps.release-please.outputs.tag_name }}
needs:
- build
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: google-github-actions/release-please-action@v4
id: release-please
with:
token: ${{ secrets.SOMLENG_PERSONAL_ACCESS_TOKEN }}
build-packages:
name: Build Packages
runs-on: ubuntu-latest
needs:
- release
if: ${{ needs.release.outputs.release_created }}
strategy:
# Note Alpine isn't supported: https://nodejs.org/api/single-executable-applications.html#platform-support
matrix:
os: [linux]
platform: [amd64, arm64]
outputs:
package_name: ${{ steps.get-package-name.outputs.package_name }}
package_version: ${{ steps.get-package-name.outputs.package_version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Packages
run: |
docker buildx build --output type=local,dest=build --platform linux/${{ matrix.platform }} --target export-${{ matrix.os }} .
- name: Get package name
id: get-package-name
run: |
package_version=$(cat build/package_version.txt)
package_name=$(cat build/package_name.txt)
full_package_name=$(cat build/full_package_name.txt)
echo "package_version=$package_version" >> $GITHUB_OUTPUT
echo "package_name=$package_name" >> $GITHUB_OUTPUT
echo "full_package_name=$full_package_name" >> $GITHUB_OUTPUT
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ steps.get-package-name.outputs.full_package_name }}
path: build/${{ steps.get-package-name.outputs.full_package_name }}
retention-days: 1
upload-packages:
name: Upload Packages
runs-on: ubuntu-latest
needs:
- build-packages
- release
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download All Artifacts
uses: actions/download-artifact@v4
with:
path: build
pattern: ${{ needs.build-packages.outputs.package_name }}-*
merge-multiple: true
- name: Add assets to Github Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
declare -a oss=("linux")
declare -a platforms=("x86_64" "aarch64")
for os in "${oss[@]}"
do
for platform in "${platforms[@]}"
do
pkg="${{ needs.build-packages.outputs.package_name }}-$os-$platform-v${{ needs.build-packages.outputs.package_version }}.zip"
cp build/${{ needs.build-packages.outputs.package_name }}-$os-$platform-v${{ needs.build-packages.outputs.package_version }} ${{ needs.build-packages.outputs.package_name }}
zip $pkg ${{ needs.build-packages.outputs.package_name }}
gh release upload ${{ needs.release.outputs.release_tag }} $pkg
done
done
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
somleng/sms-gateway
ghcr.io/somleng/sms-gateway
tags: |
# set latest tag for main branch
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=${{ needs.release.outputs.release_tag }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}