-
Notifications
You must be signed in to change notification settings - Fork 1
84 lines (71 loc) · 3.22 KB
/
main.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
name: Docker 构建和发布
on:
push:
branches:
- main
schedule:
- cron: "13 5 * * *"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: 检出仓库
uses: actions/checkout@v2
- name: 设置 Docker Buildx
uses: docker/setup-buildx-action@v1
- name: 登录到 Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 获取最新版本
id: fetch-version
run: |
LATEST_VERSION=$(wget -qO- https://hub.docker.com/v2/repositories/dushixiang/next-terminal-premium/tags | jq -r '.results[] | select(has("name") and .name != "latest" and (.name | test("cache") | not)) | .name' | head -n1)
CURRENT_VERSION=$(cat version)
echo "LATEST_VERSION: $LATEST_VERSION"
if [ "$LATEST_VERSION" = "$CURRENT_VERSION" ]; then
echo "版本匹配,跳过构建。"
echo "::set-output name=skip_build::true"
else
echo "::set-output name=latest_version::$LATEST_VERSION"
fi
- name: 构建并推送 Docker 镜像(latest)
if: steps.fetch-version.outputs.skip_build != 'true'
run: |
echo "LATEST_VERSION: $LATEST_VERSION"
docker buildx build --platform linux/amd64,linux/arm64 -t aaronlee/next-terminal-premium:latest --push .
- name: 构建并推送 Docker 镜像(带版本号)
if: steps.fetch-version.outputs.skip_build != 'true'
run: |
LATEST_VERSION=${{ steps.fetch-version.outputs.latest_version }}
echo "LATEST_VERSION: $LATEST_VERSION"
docker buildx build --platform linux/amd64,linux/arm64 -t aaronlee/next-terminal-premium:${{ steps.fetch-version.outputs.latest_version }} --push .
- name: 构建并推送 Docker 镜像(带版本号和时间戳)
if: steps.fetch-version.outputs.skip_build != 'true'
run: |
LATEST_VERSION=${{ steps.fetch-version.outputs.latest_version }}
TIMESTAMP=$(date +%Y%m%d%H%M%S)
docker buildx build --platform linux/amd64,linux/arm64 -t aaronlee/next-terminal-premium:${{ steps.fetch-version.outputs.latest_version }}-${TIMESTAMP} --push .
- name: 更新版本文件并推送到 GitHub
if: steps.fetch-version.outputs.skip_build != 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
LATEST_VERSION=${{ steps.fetch-version.outputs.latest_version }}
echo $LATEST_VERSION > version
git config user.email "[email protected]"
git config user.name "GitHub Actions"
git add version
git commit -m "镜像版本为$LATEST_VERSION"
git push origin main
- name: 写入时间到文件
run: echo $(date +"%Y-%m-%d %H:%M:%S") > time
- name: 提交和推送时间更改
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
git add time
current_time=$(TZ='Asia/Shanghai' date "+%Y-%m-%d %H:%M:%S")
git commit -m "运行时间 - 北京时间: $current_time"
git push origin main