From de5e611b2b2727aaac6693a1eacbce32e04ff963 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 19 Jan 2020 04:11:50 +0000 Subject: [PATCH] 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}"