From de5e611b2b2727aaac6693a1eacbce32e04ff963 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 19 Jan 2020 04:11:50 +0000 Subject: [PATCH 01/13] initial version --- Dockerfile | 7 +++++++ LICENSE | 21 ++++++++++++++++++++ action.yml | 23 ++++++++++++++++++++++ entrypoint.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 action.yml create mode 100755 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c376e72 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM alpine:3.10 + +RUN apk --no-cache add git jq curl + +COPY entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4fecb82 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 haya14busa + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..e1dcdd6 --- /dev/null +++ b/action.yml @@ -0,0 +1,23 @@ +name: 'Bump version in code to latest semantic ver release' +description: 'Bump version in code to latest semantic ver release. (e.g. REVIEWDOG=0.9.17 in Dockerfile)' +author: 'haya14busa' +inputs: + github_token: + description: 'GITHUB_TOKEN to get latest version with GitHub Release API' + default: '${{ github.token }}' + file: + description: 'target file' + required: true + version_name: + description: 'target version name. e.g. REVIEWDOG_VERSION' + required: true + repo: + description: 'target GitHub repository. e.g. reviewdog/reviewdog' + required: true +runs: + using: 'docker' + image: 'Dockerfile' +# Ref: https://haya14busa.github.io/github-action-brandings/ +branding: + icon: 'refresh-cw' + color: 'orange' diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..256db03 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,53 @@ +#!/bin/sh +set -e + +if [ ! -z "${GITHUB_WORKSPACE}" ]; then + cd "${GITHUB_WORKSPACE}" || exit +fi + +FILE="${INPUT_FILE:-Dockerfile}" +REPO="${INPUT_REPO:-reviewdog/reviewdog}" +VERSION_NAME="${INPUT_VERSION_NAME:-REVIEWDOG_VERSION}" + +# Get current version. +CURRENT_VERSION=$(grep -oP "${VERSION_NAME}=\K\d+\.\d+\.\d+" "${FILE}") +if [ -z "${CURRENT_VERSION}" ]; then + echo "cannot parse ${VERSION_NAME}" + exit 1 +fi +echo "Current ${VERSION_NAME}=${CURRENT_VERSION}" + +# Get latest semantic version release tag name from GitHub Release API. +GITHUB_AUTH_HEADER="" +if [ ! -z "${INPUT_GITHUB_TOKEN}" ]; then + GITHUB_AUTH_HEADER="-H \"Authorization: token ${INPUT_GITHUB_TOKEN}\"" + echo "Use INPUT_GITHUB_TOKEN to get release data." +else + echo "INPUT_GITHUB_TOKEN is not available. Subscequent GitHub API call can fail due to API limit." +fi + +LATEST_VERSION=$(\ + curl -s ${GITHUB_AUTH_HEADER} https://api.github.com/repos/${REPO}/releases | \ + jq -r '.[] | .tag_name' | \ + sed 's/^v//' | \ + grep -P '\d+\.\d+\.\d+' | \ + sort --version-sort --reverse | \ + head -n1 +) +if [ -z "${LATEST_VERSION}" ]; then + echo "cannot get latest ${REPO} version" + exit 1 +fi +echo "Latest ${VERSION_NAME}=${LATEST_VERSION}" + +if [ "${CURRENT_VERSION}" = "${LATEST_VERSION}" ]; then + echo "${VERSION_NAME} is latest. Nothing to do." + exit 0 +fi + +echo "Updating ${VERSION_NAME} to ${LATEST_VERSION} in ${FILE}" +sed -i "s/\(${VERSION_NAME}=\)\([0-9]\+\.[0-9]\+\.\?[0-9]\+\)/\1${LATEST_VERSION}/" "${FILE}" + +echo "Updated. Commit and create Pull-Request as you need." +echo "::set-output name=current::${CURRENT_VERSION}" +echo "::set-output name=latest::${LATEST_VERSION}" From a9235f700775bf3bf166db76dc583dc62df8fc6a Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 19 Jan 2020 04:16:07 +0000 Subject: [PATCH 02/13] Add Docker Image CI --- .github/workflows/dockerimage.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .github/workflows/dockerimage.yml diff --git a/.github/workflows/dockerimage.yml b/.github/workflows/dockerimage.yml new file mode 100644 index 0000000..a601c83 --- /dev/null +++ b/.github/workflows/dockerimage.yml @@ -0,0 +1,9 @@ +name: Docker Image CI +on: [push] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Build the Docker image + run: docker build . --file Dockerfile --tag ${{ github.repository }}:$(date +%s) From 90969dc026bb73dcd6e56555f22836d2a0800d42 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 19 Jan 2020 04:16:18 +0000 Subject: [PATCH 03/13] Add haya14busa/action-update-semver@v1 --- .github/workflows/update_semver.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/workflows/update_semver.yml diff --git a/.github/workflows/update_semver.yml b/.github/workflows/update_semver.yml new file mode 100644 index 0000000..8e832ec --- /dev/null +++ b/.github/workflows/update_semver.yml @@ -0,0 +1,15 @@ +name: Update Semver +on: + push: + branches-ignore: + - '**' + tags: + - 'v*.*.*' +jobs: + update-semver: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: haya14busa/action-update-semver@v1 + with: + github_token: ${{ secrets.github_token }} From 77c6f9c9e115193a0e71e77ccd53520f983722c7 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 19 Jan 2020 04:25:18 +0000 Subject: [PATCH 04/13] Add test workflow --- .github/workflows/dockerimage.yml | 6 +++++- .github/workflows/test.yml | 20 ++++++++++++++++++++ testdata/testfile | 6 ++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test.yml create mode 100644 testdata/testfile diff --git a/.github/workflows/dockerimage.yml b/.github/workflows/dockerimage.yml index a601c83..a9822c5 100644 --- a/.github/workflows/dockerimage.yml +++ b/.github/workflows/dockerimage.yml @@ -1,5 +1,9 @@ name: Docker Image CI -on: [push] +on: + push: + branches: + - master + pull_request: jobs: build: runs-on: ubuntu-latest diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..9f69c41 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,20 @@ +name: Test +on: + push: + branches: + - master + pull_request: +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ./ + id: autobump + with: + file: testdata/testfile + version_name: REVIEWDOG_VERSION + repo: reviewdog/reviewdog + + - name: Check diff + run: git diff diff --git a/testdata/testfile b/testdata/testfile new file mode 100644 index 0000000..501c049 --- /dev/null +++ b/testdata/testfile @@ -0,0 +1,6 @@ +This is test file. + +REVIEWDOG_VERSION=0.1.0 + +The above version should be updated to the latest version with this action. + From a04caab1af911483b7f3344c0627767d3e0c924e Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 19 Jan 2020 04:27:39 +0000 Subject: [PATCH 05/13] apt add grep as well to get latest version --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c376e72..13085cd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM alpine:3.10 -RUN apk --no-cache add git jq curl +RUN apk --no-cache add git jq curl grep COPY entrypoint.sh /entrypoint.sh From 77fbe68d43b5924045ef25d8cee01278f9826057 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 19 Jan 2020 04:28:57 +0000 Subject: [PATCH 06/13] add coreutils for sort -V --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 13085cd..0d29f94 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM alpine:3.10 -RUN apk --no-cache add git jq curl grep +RUN apk --no-cache add git jq curl grep coreutils COPY entrypoint.sh /entrypoint.sh From 39ad73ad8c4f08c5abdbc5e758514eb4747a02b3 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 19 Jan 2020 04:33:43 +0000 Subject: [PATCH 07/13] introduce reviewdog/action-shellcheck --- .github/workflows/reviewdog.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/workflows/reviewdog.yml diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml new file mode 100644 index 0000000..af4188b --- /dev/null +++ b/.github/workflows/reviewdog.yml @@ -0,0 +1,16 @@ +name: reviewdog +on: + push: + branches: + - master + pull_request: +jobs: + shellcheck: + name: runner / shellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: reviewdog/action-shellcheck@v1 + with: + github_token: ${{ secrets.github_token }} + reporter: github-check From f5c529d9a1bcbdcb97d203488050b1864c43c59f Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 19 Jan 2020 04:36:49 +0000 Subject: [PATCH 08/13] Use warning for shellcheck --- .github/workflows/reviewdog.yml | 1 + .github/workflows/test.yml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml index af4188b..6d502d5 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/reviewdog.yml @@ -14,3 +14,4 @@ jobs: with: github_token: ${{ secrets.github_token }} reporter: github-check + level: warning diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9f69c41..450c99c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: ./ + - uses: . id: autobump with: file: testdata/testfile From 6edb19b92ef69567cde3b90116e5704027b06464 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 19 Jan 2020 05:54:32 +0000 Subject: [PATCH 09/13] tweak reviewdog reporter --- .github/workflows/reviewdog.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml index 6d502d5..2d6fea3 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/reviewdog.yml @@ -10,8 +10,14 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - uses: haya14busa/action-cond@v1 + id: reporter + with: + cond: ${{ github.event_name == 'pull_request' }} + if_true: "github-pr-review" + if_false: "github-check" - uses: reviewdog/action-shellcheck@v1 with: github_token: ${{ secrets.github_token }} - reporter: github-check + reporter: ${{ steps.reporter.outputs.value }} level: warning From c1da361dcaf0e6da3740350857ceda548d3d7ab4 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 19 Jan 2020 05:55:28 +0000 Subject: [PATCH 10/13] fix test --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 450c99c..9f69c41 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: . + - uses: ./ id: autobump with: file: testdata/testfile From 0f5b75005133f89dd9bfea8b16016293f00927ba Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 19 Jan 2020 06:00:46 +0000 Subject: [PATCH 11/13] fix shellcheck errors --- entrypoint.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 256db03..0b1e874 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,7 +1,7 @@ #!/bin/sh set -e -if [ ! -z "${GITHUB_WORKSPACE}" ]; then +if [ -n "${GITHUB_WORKSPACE}" ]; then cd "${GITHUB_WORKSPACE}" || exit fi @@ -18,16 +18,16 @@ fi echo "Current ${VERSION_NAME}=${CURRENT_VERSION}" # Get latest semantic version release tag name from GitHub Release API. -GITHUB_AUTH_HEADER="" -if [ ! -z "${INPUT_GITHUB_TOKEN}" ]; then - GITHUB_AUTH_HEADER="-H \"Authorization: token ${INPUT_GITHUB_TOKEN}\"" +GITHUB_AUTH_HEADER=() +if [ -n "${INPUT_GITHUB_TOKEN}" ]; then + GITHUB_AUTH_HEADER=(-H "Authorization: token ${INPUT_GITHUB_TOKEN}") echo "Use INPUT_GITHUB_TOKEN to get release data." else echo "INPUT_GITHUB_TOKEN is not available. Subscequent GitHub API call can fail due to API limit." fi LATEST_VERSION=$(\ - curl -s ${GITHUB_AUTH_HEADER} https://api.github.com/repos/${REPO}/releases | \ + curl -s ${GITHUB_AUTH_HEADER[@]} "https://api.github.com/repos/${REPO}/releases" | \ jq -r '.[] | .tag_name' | \ sed 's/^v//' | \ grep -P '\d+\.\d+\.\d+' | \ From 4b16828cda7b195d32722f0adf4a78816a5c159a Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 19 Jan 2020 06:10:10 +0000 Subject: [PATCH 12/13] fix https://github.com/koalaman/shellcheck/wiki/SC2039 --- entrypoint.sh | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 0b1e874..b0b8295 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -18,16 +18,17 @@ fi echo "Current ${VERSION_NAME}=${CURRENT_VERSION}" # Get latest semantic version release tag name from GitHub Release API. -GITHUB_AUTH_HEADER=() -if [ -n "${INPUT_GITHUB_TOKEN}" ]; then - GITHUB_AUTH_HEADER=(-H "Authorization: token ${INPUT_GITHUB_TOKEN}") - echo "Use INPUT_GITHUB_TOKEN to get release data." -else - echo "INPUT_GITHUB_TOKEN is not available. Subscequent GitHub API call can fail due to API limit." -fi - +list_releases() { + if [ -n "${INPUT_GITHUB_TOKEN}" ]; then + echo "Use INPUT_GITHUB_TOKEN to get release data." >&2 + curl -s -H "Authorization: token ${INPUT_GITHUB_TOKEN}" "https://api.github.com/repos/${REPO}/releases" + else + echo "INPUT_GITHUB_TOKEN is not available. Subscequent GitHub API call can fail due to API limit." >&2 + curl -s "https://api.github.com/repos/${REPO}/releases" + fi +} LATEST_VERSION=$(\ - curl -s ${GITHUB_AUTH_HEADER[@]} "https://api.github.com/repos/${REPO}/releases" | \ + list_releases | \ jq -r '.[] | .tag_name' | \ sed 's/^v//' | \ grep -P '\d+\.\d+\.\d+' | \ From 5a513c130d38bbc8526290d565e6f0e6713ab27f Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 19 Jan 2020 06:14:06 +0000 Subject: [PATCH 13/13] Introduce reviewdog/action-hadolint --- .github/workflows/reviewdog.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml index 2d6fea3..7e683dd 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/reviewdog.yml @@ -21,3 +21,20 @@ jobs: github_token: ${{ secrets.github_token }} reporter: ${{ steps.reporter.outputs.value }} level: warning + + hadolint: + name: runner / hadolint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: haya14busa/action-cond@v1 + id: reporter + with: + cond: ${{ github.event_name == 'pull_request' }} + if_true: "github-pr-review" + if_false: "github-check" + - uses: reviewdog/action-hadolint@v1 + with: + github_token: ${{ secrets.github_token }} + reporter: ${{ steps.reporter.outputs.value }} + level: warning