-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (133 loc) · 4.54 KB
/
docker-release.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
name: 'Docker Release'
on:
push:
paths:
- 'lib/**'
- '!lib/**/*.test.ts'
- 'Dockerfile'
- '.github/workflows/**'
workflow_dispatch: {}
jobs:
check-env:
permissions:
contents: none
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
check-docker: ${{ steps.check-docker.outputs.defined }}
steps:
- id: check-docker
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
if: ${{ env.DOCKER_USERNAME != '' }}
run: echo "defined=true" >> $GITHUB_OUTPUT
set-cache:
runs-on: ubuntu-latest
outputs:
cache-from: ${{ steps.final.outputs.cache-from }}
cache-to: ${{ steps.final.outputs.cache-to }}
steps:
- name: Initial check
id: check-cache
uses: actions/cache@v4
with:
path: /tmp/check-cache
key: check-cache
- name: Create dummy cache
if: steps.check-cache.outputs.cache-hit != 'true'
run: cat /proc/version > /tmp/check-cache
- name: Save cache if necessary
if: steps.check-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: /tmp/check-cache
key: check-cache
- name: Second check
if: steps.check-cache.outputs.cache-hit != 'true'
id: check-cache-again
uses: actions/cache@v4
with:
path: /tmp/check-cache
key: check-cache
- name: Finalize cache status
id: final
run: |
if [ "${{ steps.check-cache.outputs.cache-hit }}" = "true" ] || [ "${{ steps.check-cache-again.outputs.cache-hit }}" = "true" ]; then
echo "cache-from=type=gha,scope=docker-release" >> $GITHUB_OUTPUT
echo "cache-to=type=gha,mode=max,scope=docker-release" >> $GITHUB_OUTPUT
else
echo "cache-from=" >> $GITHUB_OUTPUT
echo "cache-to=" >> $GITHUB_OUTPUT
fi
rm /tmp/check-cache
release:
runs-on: ubuntu-latest
needs: [check-env, set-cache]
if: needs.check-env.outputs.check-docker == 'true'
timeout-minutes: 120
permissions:
packages: write
contents: read
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata (ordinary version)
id: meta-ordinary
uses: docker/metadata-action@v5
with:
images: |
${{ secrets.DOCKER_USERNAME }}/rsshub
ghcr.io/${{ github.repository }}
tags: |
type=raw,value=latest,enable=true
type=raw,value={{date 'YYYY-MM-DD'}},enable=true
type=sha,format=long,prefix=,enable=true
flavor: latest=false
- name: Build and push Docker image (ordinary version)
id: build-and-push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta-ordinary.outputs.tags }}
labels: ${{ steps.meta-ordinary.outputs.labels }}
platforms: linux/amd64,linux/arm/v7,linux/arm64
cache-from: ${{ needs.set-cache.outputs.cache-from }}
cache-to: ${{ needs.set-cache.outputs.cache-to }}
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
COSIGN_EXPERIMENTAL: 'true'
run: echo "${{ steps.meta-ordinary.outputs.tags }}" | xargs -I {} cosign sign --yes {}@${{ steps.build-and-push.outputs.digest }}
description:
runs-on: ubuntu-latest
needs: check-env
if: needs.check-env.outputs.check-docker == 'true'
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: ${{ secrets.DOCKER_USERNAME }}/rsshub