-
Notifications
You must be signed in to change notification settings - Fork 13
175 lines (155 loc) · 6.39 KB
/
publish.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
name: Build docker image
on:
push:
branches: [ "master" ]
# Publish semver tags as releases.
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'
required: false
default: false
type: boolean
env:
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Install the cosign tool except on PR
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@v3
with:
cosign-release: 'v2.2.4'
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ env.IMAGE_NAME }}
trigus42/qbittorrentvpn
- name: Get latest release
run: |
# Fetch release information and extract the release tag
RELEASE_TAG=$(curl -s https://api.github.com/repos/userdocs/qbittorrent-nox-static/releases/latest | jq -r '.tag_name')
echo "RELEASE_TAG=$RELEASE_TAG" | tee -a $GITHUB_ENV
echo "VERSION_NUMBER=$(echo $RELEASE_TAG | grep -P "\d(\.\d+)+" -o | head -n 1)" | tee -a $GITHUB_ENV
- name: Setup vars
run: |
echo "DATE=$(date -u +%Y%m%d)" | tee -a $GITHUB_ENV
echo "SHORT_SHA=$(git rev-parse --short HEAD)" | tee -a $GITHUB_ENV
# Build and push Docker image with Buildx (don't push on PR)
- name: Build and push Docker image
if: github.event_name != 'pull_request' && github.ref_name == 'master'
id: build-and-push-master
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
push: ${{ github.event_name != 'pull_request' && inputs.push }}
build-args: |
"SOURCE_COMMIT=${{ env.SHORT_SHA }}"
"QBITTORRENT_TAG"="${{ env.RELEASE_TAG }}"
tags: |
ghcr.io/trigus42/alpine-qbittorrentvpn:latest
ghcr.io/trigus42/alpine-qbittorrentvpn:${{ github.head_ref || github.ref_name }}
ghcr.io/trigus42/alpine-qbittorrentvpn:${{ github.sha }}
ghcr.io/trigus42/alpine-qbittorrentvpn:qbt${{ env.VERSION_NUMBER }}
ghcr.io/trigus42/alpine-qbittorrentvpn:${{ github.sha }}-qbt${{ env.VERSION_NUMBER }}
ghcr.io/trigus42/alpine-qbittorrentvpn:qbt${{ env.VERSION_NUMBER }}-${{ env.DATE }}
trigus42/qbittorrentvpn:latest
trigus42/qbittorrentvpn:${{ github.head_ref || github.ref_name }}
trigus42/qbittorrentvpn:${{ github.sha }}
trigus42/qbittorrentvpn:qbt${{ env.VERSION_NUMBER }}
trigus42/qbittorrentvpn:${{ github.sha }}-qbt${{ env.VERSION_NUMBER }}
trigus42/qbittorrentvpn:qbt${{ env.VERSION_NUMBER }}-${{ env.DATE }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Build and push Docker image with Buildx (don't push on PR)
- name: Build and push Docker image
if: github.ref_name != 'master'
id: build-and-push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
build-args: |
"SOURCE_COMMIT=${{ env.SHORT_SHA }}"
tags: |
ghcr.io/trigus42/alpine-qbittorrentvpn:${{ github.head_ref || github.ref_name }}
ghcr.io/trigus42/alpine-qbittorrentvpn:${{ github.head_ref || github.ref_name }}-${{ github.sha }}
trigus42/qbittorrentvpn:${{ github.head_ref || github.ref_name }}
trigus42/qbittorrentvpn:${{ github.head_ref || github.ref_name }}-${{ github.sha }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Sign the resulting Docker image digest except on PRs.
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
COSIGN_EXPERIMENTAL: "true"
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: |
if [ -n "${{ steps.build-and-push-master.outputs.digest }}" ]; then
echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign --yes {}@${{ steps.build-and-push-master.outputs.digest }}
else
echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign --yes {}@${{ steps.build-and-push.outputs.digest }}
fi
# For use in check_update workflow
- name: Store artifacts
if: github.event_name != 'pull_request' && github.ref_name == 'master'
run: |
# Store the newly fetched release version in a file
echo "${{ env.RELEASE_TAG }}" > qbt-release-info
echo "Saved ${{ env.RELEASE_TAG }} to qbt-release-info"
- name: Upload new artifacts
if: github.event_name != 'pull_request' && github.ref_name == 'master'
uses: actions/upload-artifact@v4
with:
name: qbt-release-info
path: qbt-release-info