forked from jaymoulin/docker-jdownloader
-
-
Notifications
You must be signed in to change notification settings - Fork 1
155 lines (150 loc) · 5.8 KB
/
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
153
154
155
name: "Build & Release"
# This worflow needs those secrets:
#
# DOCKERPASSWORD = Docker Hub token
on:
schedule:
- cron: '3 4 * * 1'
push:
branches:
- 'master'
- 'main'
pull_request:
types: [assigned, opened, synchronize, reopened]
env:
PLATFORMS: "linux/amd64,linux/arm/v7,linux/arm64" # Build for which platforms
DOCKER_USER: "tdeutsch" # Which user to use to login to DockerHub
#####
# To rebuild someone else's repo, do this:
#
# - New env REPOSITORY: "githubuser/githubrepo"
# - Add this to the checkout:
# with:
# repository: ${{ env.REPOSITORY }}
# - One may also need to disable hadolint, due to the quality of others Dockerfile
#####
jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Generate Build-Args
id: build-args
run: |
# echo ::set-output name=build-arg1::"buildarg1"
# echo ::set-output name=build-arg2::"buildarg2"
-
name: Bump version and push tag if needed
id: tag_version
if: github.event_name == 'push'
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: false
-
name: Create a GitHub release if new version
uses: actions/create-release@v1
if: ${{ steps.tag_version.outputs.new_tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.tag_version.outputs.new_tag }}
release_name: Release ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
-
name: Prepare
id: prep
run: |
IMAGENAME=$(echo ${{ github.repository }} | sed 's/${{ github.repository_owner }}\/docker-//g')
IMAGEPREFIX="ghcr.io/${{ github.repository_owner }}"
IMAGE="${IMAGEPREFIX}/${IMAGENAME}"
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=weekly
elif [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
VERSION=devel
fi
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
if [[ "${{ steps.tag_version.outputs.new_tag }}" != "" ]]; then
VERSION=${{ steps.tag_version.outputs.new_tag }}
fi
TAGS="${IMAGE}:${VERSION}"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
MINOR=${VERSION%.*}
MAJOR=${MINOR%.*}
TAGS="$TAGS,${IMAGE}:${MINOR},${IMAGE}:${MAJOR},${IMAGE}:latest"
# elif [ "${{ github.event_name }}" = "push" ]; then
# TAGS="$TAGS,${IMAGE}:sha-${GITHUB_SHA::8}"
fi
echo ${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=imagename::${IMAGENAME}
echo ::set-output name=version::${VERSION}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
-
name: Hadolint
uses: brpaz/[email protected]
with:
dockerfile: Dockerfile
-
name: Set up QEMU
uses: docker/[email protected]
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push
id: docker_build
uses: docker/[email protected]
with:
context: .
file: ./Dockerfile
platforms: ${{ env.PLATFORMS }}
push: true
tags: ${{ steps.prep.outputs.tags }}
build-args: |
${{ steps.build-args.outputs.build-arg1 }}
${{ steps.build-args.outputs.build-arg2 }}
labels: |
org.opencontainers.image.title=${{ steps.prep.outputs.imagename }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}
-
name: Copy to Docker Hub
id: copy_images
if: github.event_name != 'pull_request'
run: |
for i in $(echo ${{ steps.prep.outputs.tags }} | sed "s/,/ /g")
do
GHTAG=$(echo $i | sed "s/ghcr.io/docker.io/g" | sed "s/${{ github.repository_owner }}/${{ env.DOCKER_USER }}/g")
skopeo copy --all --src-creds=${{ github.repository_owner }}:${{ secrets.GITHUB_TOKEN }} --dest-creds=${{ env.DOCKER_USER }}:${{ secrets.DOCKERPASSWORD }} docker://${i} docker://${GHTAG}
done
-
name: Docker Hub Description
uses: peter-evans/[email protected]
if: github.event_name != 'pull_request'
with:
username: ${{ env.DOCKER_USER }}
password: ${{ secrets.DOCKERPASSWORD }}
repository: "${{ env.DOCKER_USER }}/${{ steps.prep.outputs.imagename }}"
short-description: ${{ github.event.repository.description }}