blob: d54ef79da3c2381539a80e86bff0964113edc041 (
plain) (
blame)
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
|
name: Docker Build and Publish
on:
push:
branches:
- 'main'
jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Check whether there are any commits since this run was last triggered and push them and/or set the output
id: should_run
if: ${{ (github.event_name == 'workflow_dispatch' && contains(github.event.inputs.message, '[main]')) }}
run: |
git config user.name github-actions
git config user.email github-actions@github.com
# Defensive: update submodules in the main branch
git checkout main
git submodule update --init --recursive --remote --rebase --force
git add .
git commit -am "Update submodules [skip ci]" --no-verify || true
git push origin main --no-verify
git checkout -
git submodule update --init --recursive --remote --rebase --force
CHANGES_COUNT=$(git diff --shortstat origin/main | wc -l)
MANUAL_REBUILD="${{ github.event_name == 'workflow_dispatch' }}"
VERSION_BUMP="${{ contains(github.event.inputs.message, '[version bump]') }}"
if [ $CHANGES_COUNT -gt 0 ] || [[ $MANUAL_REBUILD == "true" && $VERSION_BUMP == "true" ]]; then
# Do the version bump in the 'main' branch ONLY if
# there were other changes coming from the 'main' branch (or)
# this is a manual trigger with the key-phrase
git checkout main
TAG_NAME=$(npm version -m "%s [skip ci]" patch)
git commit --all --amend --no-edit --no-verify
git push origin main --no-verify
git tag -f $TAG_NAME
git push origin --tags --no-verify
fi
echo "Number of changes: $CHANGES_COUNT"
if [ $CHANGES_COUNT -eq 0 ] && [ $MANUAL_REBUILD != "true" ]; then
echo "No changes found - terminating the build"
echo "::set-output name=should_run::false"
else # changes > 0 (or) MANUAL_REBUILD=true
echo "Pushing rebased commits"
git push origin $(git rev-parse --abbrev-ref HEAD) --no-verify
fi
-
name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
# list of Docker images to use as base name for tags
images: |
${{ github.repository }}
ghcr.io/${{ github.repository }}
# generate Docker tags based on the following events/attributes
tags: |
latest
type=semver,pattern={{version}}
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
if: ${{ (github.event_name == 'workflow_dispatch' && contains(github.event.inputs.message, '[main]')) }}
uses: docker/build-push-action@v3
with:
context: .
# Due to build time, only building the one currently needed.
# If needed, we can add more platforms when requested.
platforms: "linux/amd64"
# Do not push pull requests
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
|