Deploy #218
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |