From 9834d31eea28b55b1edadc428e46b3a49c70b4d4 Mon Sep 17 00:00:00 2001 From: Artur Klauser Date: Thu, 30 Jan 2020 16:42:32 +0100 Subject: [PATCH] Add DockerHub description upon deployment When docker images have been successfully deployed and tested, update the DockerHub description with the current version of the README.md from github. This is similar to what DockerHub Autobuild does, if it were used. --- .github/workflows/test.yml | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 24e15ea1b..821754e3f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -67,8 +67,9 @@ jobs: env: # Export environment variables for all stages. DOCKER_CLI_EXPERIMENTAL: enabled # for 'docker buildx' - DOCKER_BASE: mvdan/shfmt + DOCKER_USER: mvdan DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}} + DOCKER_REPO: shfmt # We use all platforms for which FROM images in our Dockerfile are # available. DOCKER_PLATFORMS: > @@ -95,6 +96,7 @@ jobs: # Pushes tag - deploy tag name. echo "::set-env name=TAG::${GITHUB_REF/refs\/tags\//}" fi + echo "::set-env name=DOCKER_BASE::${DOCKER_USER}/${DOCKER_REPO}" - name: Install Docker buildx run: | set -vx @@ -126,8 +128,8 @@ jobs: - name: Build multi-architecture Docker images with buildx run: | set -vx - username=${DOCKER_BASE/\/*/} - echo "$DOCKER_PASSWORD" | docker login -u="$username" --password-stdin + echo "$DOCKER_PASSWORD" \ + | docker login -u="$DOCKER_USER" --password-stdin function buildx() { docker buildx build \ @@ -164,3 +166,30 @@ jobs: docker run --rm -v "$PWD:/mnt" -w '/mnt' "$image" -d myscript done done + - name: Install Node.js + uses: actions/setup-node@v1 + with: + node-version: 13.x + - name: Update DockerHub description + run: | + set -vx + npm install docker-hub-api@0.8.0 + node -e ' + const fs = require("fs"); + let readme = fs.readFileSync("README.md", "utf8"); + let dockerHubAPI = require("docker-hub-api"); + dockerHubAPI.login( + process.env.DOCKER_USER, + process.env.DOCKER_PASSWORD) + .then(function () { + let url = "https://github.com/" + process.env.GITHUB_REPOSITORY; + for (let ext of ["-alpine", ""]) { + let repo = process.env.DOCKER_REPO + ext; + dockerHubAPI.setRepositoryDescription( + process.env.DOCKER_USER, + repo, + {short: "Official " + repo + " images from " + url, + full: readme}); + } + }); + '