-
Notifications
You must be signed in to change notification settings - Fork 0
160 lines (137 loc) · 6.27 KB
/
daily-release.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
name: Daily Release
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
jobs:
release:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for changes
run: |
TAG_COUNT=$(git tag | wc -l)
if [ "$TAG_COUNT" -gt 0 ]; then
LAST_TAG=$(git describe --tags --abbrev=0)
else
echo "No tags found, assuming changes."
LAST_TAG=""
fi
if [ -n "$LAST_TAG" ]; then
CHANGES=$(git diff --name-only $LAST_TAG..HEAD)
if [ -z "$CHANGES" ]; then
echo "No changes since last tag."
echo "CHANGES_EXIST=false" >> $GITHUB_ENV
else
echo "Changes detected."
echo "CHANGES_EXIST=true" >> $GITHUB_ENV
fi
else
echo "Assuming changes due to no tags."
echo "CHANGES_EXIST=true" >> $GITHUB_ENV
fi
- name: Log in to Docker Hub
if: env.CHANGES_EXIST == 'true'
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Log in to GitHub Packages
if: env.CHANGES_EXIST == 'true'
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20
with:
username: ${{ secrets.GH_PACKAGES_USERNAME }}
password: ${{ secrets.GH_PACKAGES_PASSWORD }}
registry: ghcr.io
- name: Set up Go
if: env.CHANGES_EXIST == 'true'
uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Set up Node.js
if: env.CHANGES_EXIST == 'true'
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: "npm"
- name: Install C dependencies
if: env.CHANGES_EXIST == 'true'
run: >
sudo apt-get update && sudo apt-get install -y gcc libc6-dev
mingw-w64 gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu
- name: Create empty file in webroot
if: env.CHANGES_EXIST == 'true'
run: mkdir -p webroot && touch webroot/empty
- name: Install go dependencies
if: env.CHANGES_EXIST == 'true'
run: go install
- name: Install npm dependencies
if: env.CHANGES_EXIST == 'true'
run: npm ci
- name: Run generate
if: env.CHANGES_EXIST == 'true'
run: npm run generate
- name: Run tests
if: env.CHANGES_EXIST == 'true'
run: npm run test
- name: Build project
if: env.CHANGES_EXIST == 'true'
run: npm run build
- name: Build application
if: env.CHANGES_EXIST == 'true'
run: |
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC=gcc go build -tags 'netgo sqlite_stat4 sqlite_fts5 sqlite_math_functions sqlite_vtable' -o res-mon-linux-amd64
GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc go build -tags 'netgo sqlite_stat4 sqlite_fts5 sqlite_math_functions sqlite_vtable' -o res-mon-linux-arm64
GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=1 CC=arm-linux-gnueabihf-gcc go build -tags 'netgo sqlite_stat4 sqlite_fts5 sqlite_math_functions sqlite_vtable' -o res-mon-linux-armv7
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go build -tags 'netgo sqlite_stat4 sqlite_fts5 sqlite_math_functions sqlite_vtable' -o res-mon-windows-amd64.exe
- name: Set up Docker Buildx
if: env.CHANGES_EXIST == 'true'
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
if: env.CHANGES_EXIST == 'true'
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Calculate version
if: env.CHANGES_EXIST == 'true'
run: |
YEAR=$(date +"%Y")
MONTH=$(date +"%m")
COUNT=$(git tag | grep "^v$YEAR\.$MONTH\." | wc -l | xargs)
NEW_TAG="v$YEAR.$MONTH.$COUNT"
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV
echo "DOCKER_TAG=yertools/res-mon:$NEW_TAG" >> $GITHUB_ENV
echo "PACKAGE_TAG=ghcr.io/res-mon/res-mon:$NEW_TAG" >> $GITHUB_ENV
echo "New version: $NEW_TAG"
- name: Build and push Docker image
if: env.CHANGES_EXIST == 'true'
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/Release.Dockerfile
push: true
tags: "${{ env.DOCKER_TAG }},\
${{ env.PACKAGE_TAG }}"
builder: ${{ steps.buildx.outputs.name }}
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Set up GitHub CLI
if: env.CHANGES_EXIST == 'true'
run: gh auth setup-git
env:
GH_TOKEN: ${{ secrets.DAILY_RELEASE_ACCESS_TOKEN }}
- name: Create release
if: env.CHANGES_EXIST == 'true'
run: >
gh release create $NEW_TAG res-mon-linux-amd64
res-mon-linux-arm64 res-mon-linux-armv7
res-mon-windows-amd64.exe --generate-notes
env:
GH_TOKEN: ${{ secrets.DAILY_RELEASE_ACCESS_TOKEN }}