Skip to content

Commit

Permalink
Merge pull request #21 from rickstaa/improve_version_syntax_parsing
Browse files Browse the repository at this point in the history
Adds new version matching syntax support
  • Loading branch information
haya14busa authored Dec 13, 2020
2 parents 4dde9f8 + dbc172b commit f71e4e4
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/depup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand All @@ -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 }}"
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Files to ignore

# Folders to ignore
.vscode/
*.code-workspace
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
16 changes: 9 additions & 7 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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}"
20 changes: 20 additions & 0 deletions testdata/testfile
Original file line number Diff line number Diff line change
@@ -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.

Expand Down

0 comments on commit f71e4e4

Please sign in to comment.