58 lines
1.7 KiB
YAML
58 lines
1.7 KiB
YAML
name: Publish Docker image to GHCR
|
||
|
||
on:
|
||
push:
|
||
branches: [master]
|
||
paths:
|
||
- 'Dockerfile'
|
||
- 'server.js'
|
||
- 'package.json'
|
||
- 'app/**'
|
||
- '.github/workflows/docker-publish.yml'
|
||
workflow_dispatch:
|
||
|
||
permissions:
|
||
contents: read
|
||
packages: write
|
||
|
||
jobs:
|
||
build-push:
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- name: Checkout
|
||
uses: actions/checkout@v4
|
||
|
||
- name: Log in to GitHub Container Registry
|
||
uses: docker/login-action@v3
|
||
with:
|
||
registry: ghcr.io
|
||
username: ${{ github.actor }}
|
||
password: ${{ secrets.GITHUB_TOKEN }}
|
||
|
||
- name: Build and push
|
||
uses: docker/build-push-action@v6
|
||
with:
|
||
context: .
|
||
push: true
|
||
tags: |
|
||
ghcr.io/${{ github.repository_owner }}/moyu-qile:latest
|
||
ghcr.io/${{ github.repository_owner }}/moyu-qile:${{ github.run_number }}
|
||
ghcr.io/${{ github.repository_owner }}/moyu-qile:20261008
|
||
|
||
- name: Make package public (anonymous pull)
|
||
continue-on-error: true
|
||
env:
|
||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||
run: |
|
||
gh api -X PATCH "/user/packages/container/moyu-qile" -f visibility=public \
|
||
&& echo "✅ 已设为 public" \
|
||
|| echo "⚠️ 未能通过 API 设为 public(若匿名拉取失败,需在 GitHub → Packages → moyu-qile 手动改为 Public)"
|
||
|
||
- name: Verify anonymous pull
|
||
continue-on-error: true
|
||
run: |
|
||
docker logout ghcr.io
|
||
docker manifest inspect ghcr.io/${{ github.repository_owner }}/moyu-qile:latest >/dev/null \
|
||
&& echo "✅ 匿名可拉取(public 生效)" \
|
||
|| echo "⚠️ 匿名仍不可拉取(包还是 private)"
|