diff --git a/.github/workflows/depup.yml b/.github/workflows/depup.yml index d2f10a3..7a48f2f 100644 --- a/.github/workflows/depup.yml +++ b/.github/workflows/depup.yml @@ -19,7 +19,7 @@ jobs: repo: reviewdog/reviewdog - name: Create Pull Request - uses: peter-evans/create-pull-request@v2 + uses: peter-evans/create-pull-request@v3 with: token: ${{ secrets.GITHUB_TOKEN }} title: "chore(deps): update reviewdog to ${{ steps.depup.outputs.latest }}" @@ -43,7 +43,7 @@ jobs: repo: redpen-cc/redpen - name: Create Pull Request - uses: peter-evans/create-pull-request@v2 + uses: peter-evans/create-pull-request@v3 with: token: ${{ secrets.GITHUB_TOKEN }} title: "chore(deps): update redpen to ${{ steps.depup.outputs.latest }}" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3474307 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +# Files to ignore + +# Folders to ignore +.vscode/ +*.code-workspace \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 0d29f94..2b184d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM alpine:3.10 -RUN apk --no-cache add git jq curl grep coreutils +RUN apk --no-cache add git jq curl grep coreutils perl COPY entrypoint.sh /entrypoint.sh diff --git a/README.md b/README.md index 2cb1573..bf680d1 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ jobs: repo: reviewdog/reviewdog - name: Create Pull Request - uses: peter-evans/create-pull-request@v2 + uses: peter-evans/create-pull-request@v3 with: token: ${{ secrets.GITHUB_TOKEN }} title: "chore(deps): update reviewdog to ${{ steps.depup.outputs.latest }}" diff --git a/entrypoint.sh b/entrypoint.sh index 40ecd25..4b47069 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -5,12 +5,13 @@ if [ -n "${GITHUB_WORKSPACE}" ]; then cd "${GITHUB_WORKSPACE}" || exit fi -FILE="${INPUT_FILE:-Dockerfile}" +FILE="${INPUT_FILE:-testdata/testfile}" REPO="${INPUT_REPO:-reviewdog/reviewdog}" VERSION_NAME="${INPUT_VERSION_NAME:-REVIEWDOG_VERSION}" # Get current version. -CURRENT_VERSION=$(grep -oP "${VERSION_NAME}\s*(=|:?)\s*(\'|\")?v?\K\d+\.\d+(\.\d+)?" "${FILE}" | head -n1) +# NOTE: Go to https://regex101.com/r/t1JcmL/13 To see the current regex in action. +CURRENT_VERSION=$(grep -oP "${VERSION_NAME}(?:\s*=\s*|:?\s*)[\"|\']?v?\K\d+\.\d+(\.\d+)?(-[^\'\"\s]*)?" "${FILE}" | head -n1) if [ -z "${CURRENT_VERSION}" ]; then echo "cannot parse ${VERSION_NAME}" exit 1 @@ -26,13 +27,13 @@ list_releases() { curl -s "https://api.github.com/repos/${REPO}/releases" fi } -LATEST_VERSION=$(\ +LATEST_VERSION="$(\ list_releases | \ jq -r '.[] | .tag_name' | \ - grep -oP '\d+\.\d+(\.\d+)?$' | \ + grep -oP '\d+\.\d+(\.\d+)?(-[^'\''\"\s]*)?$' | \ sort --version-sort --reverse | \ - head -n1 -) + head -n1 \ +)" if [ -z "${LATEST_VERSION}" ]; then echo "cannot get latest ${REPO} version" exit 1 @@ -45,8 +46,9 @@ if [ "${CURRENT_VERSION}" = "${LATEST_VERSION}" ]; then fi echo "Updating ${VERSION_NAME} to ${LATEST_VERSION} in ${FILE}" -sed -i "s/\(${VERSION_NAME}\s*\(=\|:\?\)\s*\('\|\"\)\?v\?\)\([0-9]\+\.[0-9]\+\(\.\?[0-9]\+\)\?\)/\1${LATEST_VERSION}/" "${FILE}" +perl -i -pe "s/${VERSION_NAME}(?:\s*=\s*|:?\s*)[\"|\']?v?\K\d+\.\d+(\.\d+)?(-[^\'\"\s]*)?/${LATEST_VERSION}/g" "${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}" +echo "::set-output name=repo::${REPO}" diff --git a/testdata/testfile b/testdata/testfile index 7abc19f..3d1c073 100644 --- a/testdata/testfile +++ b/testdata/testfile @@ -1,12 +1,32 @@ This is test file. REVIEWDOG_VERSION=v0.1.0 +REVIEWDOG_VERSION = v0.1.0 REVIEWDOG_VERSION=0.1.0 +REVIEWDOG_VERSION = 0.1.0 +REVIEWDOG_VERSION="v0.1.0" +REVIEWDOG_VERSION='v0.1.0' +REVIEWDOG_VERSION = "v0.1.0" +REVIEWDOG_VERSION = 'v0.1.0' +REVIEWDOG_VERSION="0.1.0" +REVIEWDOG_VERSION='0.1.0' +REVIEWDOG_VERSION = "0.1.0" +REVIEWDOG_VERSION = '0.1.0' +REVIEWDOG_VERSION="v0.1.0-nightly20201208+12faa31" +REVIEWDOG_VERSION='v0.1.0-nightly20201208+12faa31' +REVIEWDOG_VERSION = "v0.1.0-nightly20201208+12faa31" +REVIEWDOG_VERSION = 'v0.1.0-nightly20201208+12faa31' +REVIEWDOG_VERSION="0.1.0-nightly20201208+12faa31" +REVIEWDOG_VERSION='0.1.0-nightly20201208+12faa31' +REVIEWDOG_VERSION = "0.1.0-nightly20201208+12faa31" +REVIEWDOG_VERSION = '0.1.0-nightly20201208+12faa31' ENV REVIEWDOG_VERSION=0.1.0 ENV REVIEWDOG_VERSION 0.1.0 ARG REVIEWDOG_VERSION=0.1.0 yaml: REVIEWDOG_VERSION: 0.1.0 + REVIEWDOG_VERSION: "0.1.0" + REVIEWDOG_VERSION: '0.1.0' The above version should be updated to the latest version with this action.