-
Notifications
You must be signed in to change notification settings - Fork 13
131 lines (118 loc) · 4 KB
/
build.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: Build Docker Image
on:
push:
branches: [ "master" ]
tags: [ 'v*.*.*' ]
paths:
- '.github/workflows/**'
- 'rootfs/**'
- 'build/**'
- 'Dockerfile'
pull_request:
branches: [ "master" ]
paths:
- '.github/workflows/**'
- 'rootfs/**'
- 'build/**'
- 'Dockerfile'
workflow_dispatch:
inputs:
push:
description: 'Push image to registry'
default: false
type: boolean
update_artifact:
description: 'Update last build version info'
default: false
type: boolean
qbt_tag:
description: 'qBittorrent tag'
required: false
type: string
docker_tag:
description: 'Tag for the docker image'
required: false
type: string
commit_sha:
description: 'Commit SHA to checkout'
required: false
type: string
jobs:
build-and-sign:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Evaluate run triggers
id: triggers
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ inputs.push }}" != "true" ]]; then
echo "Workflow was manually triggered, but push is disabled. Skipping push."
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "Pull request event detected. Skipping push."
else
echo "do_push=true" >> $GITHUB_OUTPUT
fi
- name: Checkout repository
uses: actions/checkout@v4
- name: Get version infos
id: version_info
uses: ./.github/actions/build-push-info
with:
qbt_tag: ${{ inputs.qbt_tag }}
docker_tag: ${{ inputs.docker_tag }}
commit_sha: ${{ inputs.commit_sha }}
- name: Setup Docker
uses: ./.github/actions/docker-setup
with:
login_enabled: ${{ steps.triggers.outputs.do_push == 'true' }}
github_token: ${{ secrets.GITHUB_TOKEN }}
dockerhub_username: ${{ vars.DOCKERHUB_USERNAME }}
dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository }}
trigus42/qbittorrentvpn
- name: Checkout custom commit before building
uses: actions/checkout@v4
if: ${{ inputs.commit_sha }}
with:
ref: ${{ inputs.commit_sha }}
- name: Build and push Docker image
id: build
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
push: ${{ steps.triggers.outputs.do_push == 'true' }}
build-args: |
"SOURCE_COMMIT=${{ steps.version_info.outputs.build_sha_short }}"
"QBITTORRENT_TAG=${{ steps.version_info.outputs.qbt_release_tag }}"
tags: ${{ steps.version_info.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Checkout back to current commit
if: ${{ inputs.commit_sha }}
run: git checkout ${{ github.sha }}
- name: Sign Docker image
if: ${{ steps.triggers.outputs.do_push == 'true' }}
uses: ./.github/actions/sign-docker-image
with:
digest: ${{ steps.build.outputs.digest }}
tags: ${{ steps.version_info.outputs.tags }}
- name: Store qBt version
if: ${{ steps.triggers.outputs.do_push == 'true' && inputs.update_artifact != 'false' }}
run: |
echo "${{ steps.version_info.outputs.qbt_release_tag }}" | tee -a qbt-release-info
- name: Upload artifacts
if: ${{ steps.triggers.outputs.do_push == 'true' && inputs.update_artifact != 'false' }}
uses: actions/upload-artifact@v4
with:
name: qbt-release-info
path: qbt-release-info