name: Docker Build and Push on: push: branches: - main tags: - 'v*' workflow_dispatch: env: DOCKERHUB_IMAGE: dnslin/aria2bot GHCR_IMAGE: ghcr.io/${{ github.repository }} jobs: build: runs-on: ubuntu-latest permissions: contents: write packages: write steps: - name: Checkout uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Login to Docker Hub uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata id: meta uses: docker/metadata-action@v5 with: images: | ${{ env.DOCKERHUB_IMAGE }} ${{ env.GHCR_IMAGE }} tags: | type=ref,event=branch type=semver,pattern={{version}} type=semver,pattern={{major}}.{{minor}} type=sha,prefix=sha- type=raw,value=latest,enable={{is_default_branch}} - name: Build and push uses: docker/build-push-action@v6 with: context: . push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max - name: Create Release if: startsWith(github.ref, 'refs/tags/v') uses: softprops/action-gh-release@v2 with: generate_release_notes: true body: | ## Docker 镜像 ```bash # Docker Hub docker pull dnslin/aria2bot:${{ github.ref_name }} # GitHub Container Registry docker pull ghcr.io/${{ github.repository }}:${{ github.ref_name }} ```