update #69
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: update | |
on: | |
# 定期触发此 workflow (例如每周更新一次) | |
schedule: | |
- cron: '23 17 * * *' # 每天的北京时间1:23 AM (即UTC时间每天的17:23) | |
push: | |
branches: | |
- main # 监听对 main 分支的代码推送 | |
pull_request: | |
branches: | |
- main # 监听对 main 分支的 PR 合并 | |
# 手动触发工作流 | |
workflow_dispatch: | |
jobs: | |
update-build-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: 检出仓库代码 | |
uses: actions/checkout@main | |
- name: 获取当前时间并定义镜像标签 | |
id: vars | |
run: | | |
# 获取当前时间,格式为 YYYYMMDD | |
export DATE_TAG=$(date +'%Y%m%d') | |
echo "DATE_TAG=${DATE_TAG}" >> $GITHUB_ENV | |
shell: bash | |
- name: 构建 squoosh 的 Docker 镜像 | |
run: | | |
# 构建两个标签的镜像:latest 和基于日期的标签 | |
docker build -t ${{ secrets.DOCKER_USERNAME }}/squoosh:${{ env.DATE_TAG }} -t ${{ secrets.DOCKER_USERNAME }}/squoosh:latest . | |
- name: 登录 Docker Hub | |
uses: docker/login-action@master | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: 推送 Docker 镜像到 Docker Hub | |
run: | | |
# 推送 latest 和日期标签的镜像 | |
docker push ${{ secrets.DOCKER_USERNAME }}/squoosh:${{ env.DATE_TAG }} | |
docker push ${{ secrets.DOCKER_USERNAME }}/squoosh:latest | |
- name: 删除旧 Actions | |
uses: Mattraks/delete-workflow-runs@main | |
with: | |
token: ${{ secrets.TOKEN }} | |
repository: ${{ github.repository }} | |
retain_days: 1 | |
keep_minimum_runs: 2 |