From 15a21af2bc088473d898cf228bceaa6c7a4874cb Mon Sep 17 00:00:00 2001 From: rickstaa Date: Fri, 11 Dec 2020 15:22:02 +0100 Subject: [PATCH 1/7] :sparkles: Extends version matching with quotes and - annotated tags" In this commit I added support to match the version when it is enclosed in quotes (Example: REVIEWDOG_VERSION = "v0.1.0"). I also added support for version tags that contain a - annotation text (example: REVIEWDOG=v0.1.0-nightly20201208+12faa31). You can check out the regex syntax on https://regex101.com/r/t1JcmL/10. --- .gitignore | 4 ++++ Dockerfile | 2 +- entrypoint.sh | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7608ff0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +# Files to ignore + +# Folders to ignore +.vscode/ \ 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/entrypoint.sh b/entrypoint.sh index f652ced..2139ace 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -10,7 +10,7 @@ REPO="${INPUT_REPO:-reviewdog/reviewdog}" VERSION_NAME="${INPUT_VERSION_NAME:-REVIEWDOG_VERSION}" # Get current version. -CURRENT_VERSION=$(grep -oP "${VERSION_NAME}(=|:?\s+)v?\K\d+\.\d+(\.\d+)?" "${FILE}" | head -n1) +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 @@ -45,7 +45,7 @@ if [ "${CURRENT_VERSION}" = "${LATEST_VERSION}" ]; then fi echo "Updating ${VERSION_NAME} to ${LATEST_VERSION} in ${FILE}" -sed -i "s/\(${VERSION_NAME}\(=\|:\?\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}" From b72f443043d9a9bc19769bc2e8b8b98a3f05df1c Mon Sep 17 00:00:00 2001 From: rickstaa Date: Fri, 11 Dec 2020 15:31:30 +0100 Subject: [PATCH 2/7] :white_check_mark: Updates testfile with new supported syntax --- testdata/testfile | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/testdata/testfile b/testdata/testfile index eb921a6..5d8531b 100644 --- a/testdata/testfile +++ b/testdata/testfile @@ -1,7 +1,17 @@ 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="0.1.0" +REVIEWDOG_VERSION = "0.1.0" +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" ENV REVIEWDOG_VERSION=0.1.0 ENV REVIEWDOG_VERSION 0.1.0 ARG REVIEWDOG_VERSION=0.1.0 From 47054a1d4c7060180d4c545a4bb011dead111b1f Mon Sep 17 00:00:00 2001 From: rickstaa Date: Fri, 11 Dec 2020 16:58:40 +0100 Subject: [PATCH 3/7] :sparkles: Adds used repo as output --- entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/entrypoint.sh b/entrypoint.sh index 2139ace..a0e7e67 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -50,3 +50,4 @@ perl -i -pe "s/${VERSION_NAME}(?:\s?=\s?|:?\s+)\"?v?\K\d+\.\d+(\.\d+)?(-[^\"\s]* 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}" From 374f5b7b5b89cdeb0ba5a5f4868188dd10cb4271 Mon Sep 17 00:00:00 2001 From: rickstaa Date: Fri, 11 Dec 2020 17:21:47 +0100 Subject: [PATCH 4/7] :bug: Fixes a bug in the retrieval of the latest repo version --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index a0e7e67..42f81bc 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -29,7 +29,7 @@ list_releases() { 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 ) From 6a229db7d87ee37866236abeef2cc2b5d51a429c Mon Sep 17 00:00:00 2001 From: rickstaa Date: Sat, 12 Dec 2020 16:15:09 +0100 Subject: [PATCH 5/7] :sparkles: Adds support for single quotes --- .gitignore | 3 ++- entrypoint.sh | 14 +++++++------- testdata/testfile | 32 ++++++++++++++++---------------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 7608ff0..3474307 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # Files to ignore # Folders to ignore -.vscode/ \ No newline at end of file +.vscode/ +*.code-workspace \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index 42f81bc..61c5791 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -5,12 +5,12 @@ 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?|:?\s+)\"?v?\K\d+\.\d+(\.\d+)?(-[^\"\s]*)?" "${FILE}" | head -n1) +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 +26,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+)?(-[^\"\s]*)?$' | \ + 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,7 +45,7 @@ if [ "${CURRENT_VERSION}" = "${LATEST_VERSION}" ]; then fi echo "Updating ${VERSION_NAME} to ${LATEST_VERSION} in ${FILE}" -perl -i -pe "s/${VERSION_NAME}(?:\s?=\s?|:?\s+)\"?v?\K\d+\.\d+(\.\d+)?(-[^\"\s]*)?/${LATEST_VERSION}/g" "${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}" diff --git a/testdata/testfile b/testdata/testfile index 5d8531b..f8234c4 100644 --- a/testdata/testfile +++ b/testdata/testfile @@ -1,22 +1,22 @@ 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="0.1.0" -REVIEWDOG_VERSION = "0.1.0" -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" -ENV REVIEWDOG_VERSION=0.1.0 -ENV REVIEWDOG_VERSION 0.1.0 -ARG REVIEWDOG_VERSION=0.1.0 +REVIEWDOG_VERSION=v0.11.0 +REVIEWDOG_VERSION = v0.11.0 +REVIEWDOG_VERSION=0.11.0 +REVIEWDOG_VERSION = 0.11.0 +REVIEWDOG_VERSION="v0.11.0" +REVIEWDOG_VERSION = "v0.11.0" +REVIEWDOG_VERSION="0.11.0" +REVIEWDOG_VERSION = "0.11.0" +REVIEWDOG_VERSION="v0.11.0" +REVIEWDOG_VERSION = "v0.11.0" +REVIEWDOG_VERSION="0.11.0" +REVIEWDOG_VERSION = "0.11.0" +ENV REVIEWDOG_VERSION=0.11.0 +ENV REVIEWDOG_VERSION 0.11.0 +ARG REVIEWDOG_VERSION=0.11.0 yaml: - REVIEWDOG_VERSION: 0.1.0 + REVIEWDOG_VERSION: 0.11.0 The above version should be updated to the latest version with this action. From d15af245f4ef57e24a140e7c8aeae5e0465ed9a3 Mon Sep 17 00:00:00 2001 From: rickstaa Date: Sat, 12 Dec 2020 16:27:38 +0100 Subject: [PATCH 6/7] :white_check_mark: Updates regex syntax tests To see the new regex syntax in action go to https://regex101.com/r/t1JcmL/13. --- entrypoint.sh | 1 + testdata/testfile | 42 ++++++++++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 61c5791..4b47069 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -10,6 +10,7 @@ REPO="${INPUT_REPO:-reviewdog/reviewdog}" VERSION_NAME="${INPUT_VERSION_NAME:-REVIEWDOG_VERSION}" # Get current version. +# 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}" diff --git a/testdata/testfile b/testdata/testfile index f8234c4..8146a6f 100644 --- a/testdata/testfile +++ b/testdata/testfile @@ -1,22 +1,32 @@ This is test file. -REVIEWDOG_VERSION=v0.11.0 -REVIEWDOG_VERSION = v0.11.0 -REVIEWDOG_VERSION=0.11.0 -REVIEWDOG_VERSION = 0.11.0 -REVIEWDOG_VERSION="v0.11.0" -REVIEWDOG_VERSION = "v0.11.0" -REVIEWDOG_VERSION="0.11.0" -REVIEWDOG_VERSION = "0.11.0" -REVIEWDOG_VERSION="v0.11.0" -REVIEWDOG_VERSION = "v0.11.0" -REVIEWDOG_VERSION="0.11.0" -REVIEWDOG_VERSION = "0.11.0" -ENV REVIEWDOG_VERSION=0.11.0 -ENV REVIEWDOG_VERSION 0.11.0 -ARG REVIEWDOG_VERSION=0.11.0 +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.11.0 + 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. From e2e63124f33206a6041e3163370c33cdfce8ad41 Mon Sep 17 00:00:00 2001 From: rickstaa Date: Sat, 12 Dec 2020 16:41:42 +0100 Subject: [PATCH 7/7] :alien: Updates create-pull-request version to fix env security vurnerability This commit updates the create-pull-request action version such that a security vulnerability that is present when using the `set-env` and `add-path` arguments is fixed. See https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/ for more information. --- .github/workflows/depup.yml | 4 ++-- README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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/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 }}"