Skip to content

Publish image

Publish image #46

Workflow file for this run

name: Publish image
on:
workflow_dispatch:
inputs:
manualTag:
description: 'Manual Tag'
required: true
autoWithLatestTag:
description: 'Auto Add Latest Tag'
required: true
default: true
type: boolean
release:
types: [published]
env:
DOCKERHUB_USERNAME : ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_PASSWORD : ${{ secrets.DOCKERHUB_PASSWORD }}
GHCR_USERNAME: ${{ github.repository_owner }}
GHCR_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
DOCKER_IMG_NAME: "zai7lou/bilibili_tool_pro"
GHC_IMG_NAME: "ghcr.io/raywangqvq/bilibili_tool_pro"
jobs:
PublishImage:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: GetTargetVersion
id: getTargetVersion
run: |
TargetVersion=""
if [ "${{ github.event.release.tag_name }}" ] ; then
TargetVersion=${{ github.event.release.tag_name }}
else
TargetVersion=$(grep -oP '(?<=<Version>).*?(?=<\/Version>)' ./common.props)
fi
echo "TargetVersion: $TargetVersion"
echo "TargetVersion=$TargetVersion" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_PASSWORD }}
- name: Log in to ghcr
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ env.GHCR_USERNAME }}
password: ${{ env.GHCR_PASSWORD }}
- name: Generate tags
id: tags
run: |
targetVersion="${{ steps.getTargetVersion.outputs.TargetVersion }}"
dockerTagWithVersion="${{ env.DOCKER_IMG_NAME }}:$targetVersion"
ghcrTagWithVersion="${{ env.GHC_IMG_NAME }}:$targetVersion"
dockerTagWithLatest=""
ghcrTagWithLatest=""
if [ "${{ github.event.inputs.autoWithLatestTag }}" == "true" ] || [ ${{ github.event.release.created_at }} ]; then
dockerTagWithLatest="${{ env.DOCKER_IMG_NAME }}:latest"
ghcrTagWithLatest="${{ env.GHC_IMG_NAME }}:latest"
fi
echo "dockerTagWithVersion=$dockerTagWithVersion" >> $GITHUB_OUTPUT
echo "ghcrTagWithVersion=$ghcrTagWithVersion" >> $GITHUB_OUTPUT
echo "dockerTagWithLatest=$dockerTagWithLatest" >> $GITHUB_OUTPUT
echo "ghcrTagWithLatest=$ghcrTagWithLatest" >> $GITHUB_OUTPUT
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ steps.tags.outputs.dockerTagWithVersion }}
${{ steps.tags.outputs.ghcrTagWithVersion }}
${{ steps.tags.outputs.dockerTagWithLatest }}
${{ steps.tags.outputs.ghcrTagWithLatest }}