Skip to content

Commit 616a132

Browse files
feat: 添加构建代码
1 parent cc5cb2e commit 616a132

File tree

4 files changed

+499
-339
lines changed

4 files changed

+499
-339
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Auto detect text files and perform LF normalization
2-
* text=auto
2+
* text=lf

.github/workflows/release.yml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: build
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '0 20 * * *'
7+
8+
env:
9+
app_name: lat
10+
app_repo: lat-opensource/lat
11+
12+
jobs:
13+
check-binaries:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
app_version: ${{ steps.get-version.outputs.app_version }}
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: docker/setup-buildx-action@v3
20+
21+
- name: Get Version
22+
id: get-version
23+
run: |
24+
app_version=$(curl -sSL "https://github.com/${{ env.app_repo }}/raw/refs/heads/master/VERSION")
25+
if [ -z "${app_version}" ] || [ "${app_version}" == "null" ]; then
26+
echo "Failed to get version"
27+
exit 1
28+
fi
29+
30+
echo "app_version=${app_version}" >> $GITHUB_ENV
31+
echo "app_version=${app_version}" >> $GITHUB_OUTPUT
32+
echo ""
33+
echo "========== Build Args =========="
34+
echo "app_version=${app_version}"
35+
36+
- name: Check Release
37+
id: check-release
38+
run: |
39+
gh release view ${app_version} -R ${{ github.repository }} >/dev/null 2>&1 || echo "create=1" >> $GITHUB_OUTPUT
40+
env:
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
43+
- name: Create Tag
44+
if : steps.check-release.outputs.create == '1'
45+
run: |
46+
git config --global user.name "${GITHUB_ACTOR}"
47+
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
48+
git add .
49+
git commit -m "Release ${app_version}" || true
50+
git tag ${app_version}
51+
git push origin ${app_version} || true
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
55+
- name: Create Release
56+
if : steps.check-release.outputs.create == '1'
57+
run: |
58+
gh release create ${app_version} -R ${{ github.repository }} --title ${app_version} --generate-notes
59+
env:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
62+
build-binaries:
63+
runs-on: ubuntu-latest
64+
needs: check-binaries
65+
env:
66+
app_version: ${{ needs.check-binaries.outputs.app_version }}
67+
steps:
68+
- uses: actions/checkout@v4
69+
with:
70+
ref: ${{ env.app_version }}
71+
72+
- uses: docker/setup-qemu-action@v3
73+
- uses: docker/setup-buildx-action@v3
74+
75+
- name: Check Release
76+
id: create-binaries
77+
run: |
78+
gh release view ${{ env.app_version }} -R ${{ github.repository }} | grep ${{ env.app_name }}-x86_64 >/dev/null 2>&1 || echo "create=1" >> $GITHUB_OUTPUT
79+
env:
80+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
81+
82+
- name: Cache Docker layers
83+
if : steps.create-binaries.outputs.create == '1'
84+
uses: actions/cache@v4
85+
with:
86+
path: /tmp/.buildx-cache
87+
key: ${{ runner.os }}-buildx-${{ github.sha }}
88+
restore-keys: |
89+
${{ runner.os }}-buildx-
90+
91+
- name: Build Binaries
92+
if : steps.create-binaries.outputs.create == '1'
93+
run: |
94+
docker buildx build --platform linux/loong64 -t ${{ env.app_name }}-debian-loong64:${{ env.app_version }} --cache-from=type=local,src=/tmp/.buildx-cache --cache-to=type=local,dest=/tmp/.buildx-cache-new,mode=max debian --load
95+
96+
- name: Upgrade Release
97+
if : steps.create-binaries.outputs.create == '1'
98+
run: |
99+
docker run --rm -v $(pwd)/dist:/dist ${{ env.app_name }}-debian-loong64:${{ env.app_version }}
100+
ls -al dist
101+
gh release upload ${{ env.app_version }} -R ${{ github.repository }} dist/*
102+
env:
103+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
104+
105+
- name: Move cache
106+
if : steps.create-binaries.outputs.create == '1'
107+
run: |
108+
rm -rf /tmp/.buildx-cache
109+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

0 commit comments

Comments
 (0)