Skip to content

Docker 构建和发布 #160

Docker 构建和发布

Docker 构建和发布 #160

Workflow file for this run

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