| name: 构建并推送Docker镜像 | |
| permissions: write-all | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 检出代码 | |
| uses: actions/checkout@v4 | |
| - name: 登录到GitHub容器注册表 | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: 设置小写的用户名和仓库名称 | |
| run: | | |
| REPO_FULL_NAME=${{ github.repository }} | |
| REPO_OWNER=$(echo "${REPO_FULL_NAME}" | cut -d'/' -f1 | tr '[:upper:]' '[:lower:]') | |
| REPO_NAME=$(echo "${REPO_FULL_NAME}" | cut -d'/' -f2 | tr '[:upper:]' '[:lower:]') | |
| echo "REPO_NAME_LOWER=${REPO_OWNER}/${REPO_NAME}" >> $GITHUB_ENV | |
| - name: 构建Docker镜像 | |
| run: | | |
| docker build . -t ghcr.io/$REPO_NAME_LOWER:latest | |
| shell: bash | |
| - name: 推送Docker镜像 | |
| run: | | |
| docker push ghcr.io/$REPO_NAME_LOWER:latest | |
| shell: bash | |