-
Notifications
You must be signed in to change notification settings - Fork 1.8k
90 lines (80 loc) · 3.01 KB
/
publish-image.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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: [created]
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 }}