Merge pull request #19 from skarzi/issue-18

Handle quotes and extra whitespaces in version regexps
This commit is contained in:
haya14busa
2020-12-13 13:58:10 +09:00
committed by GitHub
3 changed files with 20 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ on:
branches: branches:
- master - master
pull_request: pull_request:
workflow_dispatch:
jobs: jobs:
test: test:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -46,3 +47,17 @@ jobs:
- name: Check diff - name: Check diff
run: git diff run: git diff
quoted_version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
id: depup
with:
file: testdata/testfile
version_name: POETRY_VERSION
repo: python-poetry/poetry
- name: Check diff
run: git diff

View File

@@ -10,7 +10,7 @@ REPO="${INPUT_REPO:-reviewdog/reviewdog}"
VERSION_NAME="${INPUT_VERSION_NAME:-REVIEWDOG_VERSION}" VERSION_NAME="${INPUT_VERSION_NAME:-REVIEWDOG_VERSION}"
# Get current 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*(\'|\")?v?\K\d+\.\d+(\.\d+)?" "${FILE}" | head -n1)
if [ -z "${CURRENT_VERSION}" ]; then if [ -z "${CURRENT_VERSION}" ]; then
echo "cannot parse ${VERSION_NAME}" echo "cannot parse ${VERSION_NAME}"
exit 1 exit 1
@@ -45,7 +45,7 @@ if [ "${CURRENT_VERSION}" = "${LATEST_VERSION}" ]; then
fi fi
echo "Updating ${VERSION_NAME} to ${LATEST_VERSION} in ${FILE}" 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}" sed -i "s/\(${VERSION_NAME}\s*\(=\|:\?\)\s*\('\|\"\)\?v\?\)\([0-9]\+\.[0-9]\+\(\.\?[0-9]\+\)\?\)/\1${LATEST_VERSION}/" "${FILE}"
echo "Updated. Commit and create Pull-Request as you need." echo "Updated. Commit and create Pull-Request as you need."
echo "::set-output name=current::${CURRENT_VERSION}" echo "::set-output name=current::${CURRENT_VERSION}"

3
testdata/testfile vendored
View File

@@ -16,3 +16,6 @@ Other test cases.
REDPEN_VERSION=1.10.1 REDPEN_VERSION=1.10.1
TMUX_VERSION=3.0 TMUX_VERSION=3.0
POETRY_VERSION="1.1.3"
ENV POETRY_VERSION='1.1.3'