-
-
Notifications
You must be signed in to change notification settings - Fork 98
149 lines (132 loc) · 5.29 KB
/
build-nightly-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
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
name: Docker nightly image CI/CD
concurrency:
group: nightly-build
cancel-in-progress: true
env:
DOCKER_IMAGE_NAME: jlesage/handbrake
PLATFORMS: linux/amd64
on:
# Run this workflow once a day.
schedule:
- cron: '0 0 * * *'
# Allows to run this workflow manually from the Actions tab.
workflow_dispatch:
jobs:
prepare:
name: Prepare
runs-on: ubuntu-20.04
# Map a step output to a job output.
outputs:
handbrake_version: ${{ steps.prep.outputs.handbrake_version }}
version: ${{ steps.prep.outputs.version }}
label_version: ${{ steps.prep.outputs.label_version }}
tags: ${{ steps.prep.outputs.tags }}
build_needed: ${{ steps.prep.outputs.build_needed }}
steps:
- name: Prepare
id: prep
run: |
# Get info about the last HandBrake commit.
HANDBRAKE_LAST_COMMIT="$(curl -s "https://api.github.com/repos/HandBrake/HandBrake/commits?page=1&per_page=1" | jq -r '.[0] | .commit.committer.date + " " + .sha')"
HANDBRAKE_LAST_COMMIT_SHORT_HASH="$(echo "$HANDBRAKE_LAST_COMMIT" | awk '{print substr($2,0,10)}')"
HANDBRAKE_LAST_COMMIT_DATE="$(env TZ=UTC date -d"$(echo "$HANDBRAKE_LAST_COMMIT" | awk '{print $1}')" +%Y%m%d%H%M%S)"
# Determine the HandBrake version.
HANDBRAKE_VERSION="nightly-${HANDBRAKE_LAST_COMMIT_DATE}-${HANDBRAKE_LAST_COMMIT_SHORT_HASH}"
# Determine the Docker nightly image version.
# NOTE: The image version is the same as the HandBrake version.
VERSION="$HANDBRAKE_VERSION"
# Determine the version to put in container label.
LABEL_VERSION="$VERSION"
# Determine the Docker container tags.
TAGS="${{ env.DOCKER_IMAGE_NAME }}:${VERSION},${{ env.DOCKER_IMAGE_NAME }}:nightly-latest"
# Determine if a build is needed.
if curl --silent -f "https://hub.docker.com/v2/repositories/${{ env.DOCKER_IMAGE_NAME }}/tags/${VERSION}/" > /dev/null
then
BUILD_NEEDED=no
else
BUILD_NEEDED=yes
fi
# Print results.
echo "::group::Results"
echo "HandBrake last commit hash: $HANDBRAKE_LAST_COMMIT_SHORT_HASH"
echo "HandBrake last commit date: $HANDBRAKE_LAST_COMMIT_DATE"
echo "HandBrake version: $HANDBRAKE_VERSION"
echo "Docker nightly image version: $VERSION"
echo "Docker nightly image version label: $LABEL_VERSION"
echo "Docker nightly image tag(s): $TAGS"
echo "Build needed: $BUILD_NEEDED"
echo "::endgroup::"
# Export outputs.
echo "handbrake_version=${HANDBRAKE_VERSION}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "label_version=${LABEL_VERSION}" >> $GITHUB_OUTPUT
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "build_needed=${BUILD_NEEDED}" >> $GITHUB_OUTPUT
build:
name: Build image
runs-on: ubuntu-20.04
needs: prepare
if: ${{ needs.prepare.outputs.build_needed == 'yes' }}
steps:
- name: Free disk space
run: |
# Free disk space.
echo "::group::Before"
df -h /
echo "::endgroup::"
echo "::group::Removing unneeded softwares and files..."
for DIR in /usr/local/lib/android /usr/share/dotnet /opt/ghc
do
if [ -d "$DIR" ]; then
echo "Removing $DIR..."
sudo rm -r "$DIR"
fi
done
echo "::endgroup::"
echo "::group::After"
df -h /
echo "::endgroup::"
- name: Checkout
uses: actions/checkout@v3
with:
ref: nightly
- name: Setup QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: arm,arm64,ppc64le,mips64,s390x
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: true
platforms: ${{ env.PLATFORMS }}
tags: ${{ needs.prepare.outputs.tags }}
build-args: |
DOCKER_IMAGE_VERSION=${{ needs.prepare.outputs.label_version }}
HANDBRAKE_VERSION=${{ needs.prepare.outputs.handbrake_version }}
HANDBRAKE_URL=https://github.com/HandBrake/HandBrake.git
HANDBRAKE_DEBUG_MODE=max
cache-from: type=gha,scope=${{ env.DOCKER_IMAGE_NAME }}-nightly
cache-to: type=gha,mode=max,scope=${{ env.DOCKER_IMAGE_NAME }}-nightly
- name: Inspect
run: |
docker buildx imagetools inspect ${{ env.DOCKER_IMAGE_NAME }}:${{ needs.prepare.outputs.version }}
notification:
name: Notification
needs: [ prepare, build ]
runs-on: ubuntu-20.04
if: ${{ always() && needs.prepare.outputs.build_needed == 'yes' }}
steps:
- name: Pushover notification
uses: desiderati/github-action-pushover@v1
with:
job-status: ${{ needs.build.result }}
pushover-api-token: ${{ secrets.PUSHOVER_API_TOKEN }}
pushover-user-key: ${{ secrets.PUSHOVER_USER_KEY }}