diff --git a/.github/workflows/dockerimage.yml b/.github/workflows/dockerimage.yml new file mode 100644 index 0000000..a9822c5 --- /dev/null +++ b/.github/workflows/dockerimage.yml @@ -0,0 +1,13 @@ +name: Docker Image CI +on: + push: + branches: + - master + pull_request: +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) diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml new file mode 100644 index 0000000..7e683dd --- /dev/null +++ b/.github/workflows/reviewdog.yml @@ -0,0 +1,40 @@ +name: reviewdog +on: + push: + branches: + - master + pull_request: +jobs: + shellcheck: + name: runner / shellcheck + 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: ${{ 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 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/.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 }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0d29f94 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM alpine:3.10 + +RUN apk --no-cache add git jq curl grep coreutils + +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..b0b8295 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,54 @@ +#!/bin/sh +set -e + +if [ -n "${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. +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=$(\ + list_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}" 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. +