-
Notifications
You must be signed in to change notification settings - Fork 2
129 lines (117 loc) · 4.57 KB
/
deploy.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
name: Deploy
on:
push:
branches:
- master
paths-ignore:
- 'docs/**'
- '**.md'
- 'LICENSE'
- '.github/workflows/test.yml'
schedule:
- cron: "0 2 * * 0" # Weekly on Sundays at 02:00
env:
DOCKER_USERNAME: tiryoh
DOCKER_IMAGENAME: ros2
GIT_CONFIG_USER: Tiryoh@GitHubActions
GIT_CONFIG_EMAIL: tiryoh@gmail.com
jobs:
build-and-deploy:
runs-on: ubuntu-latest
strategy:
matrix:
ros-distro:
- crystal
- dashing
- eloquent
- foxy
- galactic
- humble
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup QEMU
uses: docker/setup-qemu-action@v2
- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Login to docker.io
uses: docker/login-action@v2
with:
username: ${{ env.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Prepare Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: |
${{ env.DOCKER_USERNAME }}/${{ env.DOCKER_IMAGENAME }}
tags: |
type=raw,value=${{ matrix.ros-distro }}
type=raw,value=${{ matrix.ros-distro }}-{{date 'YYYYMMDDTHHmm'}}
flavor: |
latest=${{ matrix.ros-distro == 'humble' }}
prefix=
suffix=
- name: Build and Publish
id: docker-build
uses: docker/build-push-action@v2
with:
context: ${{ matrix.ros-distro }}
platforms: linux/amd64, linux/arm64
outputs: type=registry # same as --push, push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- # Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
# https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md
name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Get Current Job Log URL
id: jobs
uses: Tiryoh/gha-jobid-action@v0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
job_name: build-and-deploy (${{ matrix.ros-distro }})
- name: Update wiki
env:
DOCKER_TAGNAME: ${{ matrix.ros-distro }}
run: |
DOCKER_SNAPSHOT=$(cat << EOF | grep ".*-.*T.*" | sed -E "s/.*:(.*-[0-9]*T[0-9])/\1/g"
${{ steps.meta.outputs.tags }}
EOF)
echo $DOCKER_SNAPSHOT
DOCKER_DIGEST=${{ steps.docker-build.outputs.digest }}
echo $DOCKER_DIGEST
DOCKER_DIGEST_SHORT=$(echo ${DOCKER_DIGEST} | sed -E 's/.*([0-9a-z]{12})[0-9a-z]{52}$/\1/g')
echo $DOCKER_DIGEST_SHORT
DOCKER_SNAPSHOT_IMAGE_HISTORY_URL=$(echo "https://hub.docker.com/r/${DOCKER_USERNAME}/${DOCKER_IMAGENAME}/tags?page=1&name=${DOCKER_SNAPSHOT}")
git clone --depth=1 https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.wiki.git wiki
cd wiki
LINE=$(grep -n "add ${{ matrix.ros-distro }} msg after this line" ${{ matrix.ros-distro }}.md | cut -d ":" -f 1)
head -n $LINE ${{ matrix.ros-distro }}.md > tmp.md
echo "* \`${DOCKER_DIGEST_SHORT}\`" | tee -a tmp.md
echo " * uploaded on $(date --iso-8601="minutes")" | tee -a tmp.md
echo " * ${{ steps.jobs.outputs.html_url }}" | tee -a tmp.md
echo " * snapshot" | tee -a tmp.md
echo " * [\`${DOCKER_SNAPSHOT}\`](${DOCKER_SNAPSHOT_IMAGE_HISTORY_URL})" | tee -a tmp.md
tail -n +$(( $LINE+1 )) ${{ matrix.ros-distro }}.md >> tmp.md
mv tmp.md ${{ matrix.ros-distro }}.md
git config --local user.email "${GIT_CONFIG_EMAIL}"
git config --local user.name "${GIT_CONFIG_USER}"
git add ${{ matrix.ros-distro }}.md
git commit -m "Update ${{ matrix.ros-distro }}.md"
git fetch origin && git merge origin/master --no-edit && git push origin master || \
git fetch origin && git merge origin/master --no-edit && git push origin master