From f1460d6c46d9da91a2cf27f46d653f8d3ec155e2 Mon Sep 17 00:00:00 2001 From: nasa9084 Date: Wed, 3 Jul 2024 23:42:40 +0900 Subject: [PATCH] Support including/excluding specific version patterns --- .github/workflows/depup.yml | 16 ++++++++++++++++ .github/workflows/test.yml | 30 ++++++++++++++++++++++++++++++ action.yml | 6 ++++++ entrypoint.sh | 18 ++++++++++++++++++ testdata/testfile | 2 ++ with-pr/action.yml | 14 +++++++++++--- 6 files changed, 83 insertions(+), 3 deletions(-) diff --git a/.github/workflows/depup.yml b/.github/workflows/depup.yml index 6f37b79..a9e8b5d 100644 --- a/.github/workflows/depup.yml +++ b/.github/workflows/depup.yml @@ -43,3 +43,19 @@ jobs: repo: thinca/vim-themis tag: true labels: demo + + include: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./with-pr + id: depup + with: + file: testdata/testfile + version_name: TERRAFORM_VERSION + repo: hashicorp/terraform + include: '^\d+\.\d+\.\d+$' + labels: demo + + - name: Check diff + run: git diff diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b17bb9f..fdd3219 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -76,3 +76,33 @@ jobs: - name: Check diff run: git diff + + include: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./ + id: depup + with: + file: testdata/testfile + version_name: TERRAFORM_VERSION + repo: hashicorp/terraform + include: '^\d+\.\d+\.\d+$' + + - name: Check diff + run: git diff + + exclude: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./ + id: depup + with: + file: testdata/testfile + version_name: TERRAFORM_VERSION + repo: hashicorp/terraform + exclude: '-(alpha|beta|rc)' + + - name: Check diff + run: git diff diff --git a/action.yml b/action.yml index 0fbb088..cbf2da8 100644 --- a/action.yml +++ b/action.yml @@ -18,6 +18,12 @@ inputs: description: 'Check tags instead of releases.' default: 'false' required: false + include: + description: 'Regular expression to use only matched versions.' + required: false + exclude: + description: 'Regular expression not to use matched versions.' + required: false outputs: current: description: 'current version' diff --git a/entrypoint.sh b/entrypoint.sh index 8e20c71..a7fcf86 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -37,6 +37,23 @@ list_versions() { fi } +# Filter given version list using given include/exclude regular expressions. +filter_versions() { + list=$(cat) + + if [ -n "${INPUT_INCLUDE}" ]; then + echo "include pattern: ${INPUT_INCLUDE}" >&2 + list="$(echo "${list}" | grep -P -- "${INPUT_INCLUDE}")" + fi + + if [ -n "${INPUT_EXCLUDE}" ]; then + echo "exclude pattern: ${INPUT_EXCLUDE}" >&2 + list="$(echo "${list}" | grep -vP -- "${INPUT_EXCLUDE}")" + fi + + echo "${list}" +} + set_output() { name=$1 value=$2 @@ -50,6 +67,7 @@ set_output() { LATEST_VERSION="$(\ list_versions | \ grep -oP '\d+(\.\d+)+(-[^'\''\"\s]*)?$'| \ + filter_versions | \ sort --version-sort --reverse | \ head -n1 \ )" diff --git a/testdata/testfile b/testdata/testfile index 2e9cf8e..cc7f83c 100644 --- a/testdata/testfile +++ b/testdata/testfile @@ -41,3 +41,5 @@ POETRY_VERSION="1.1.3" ENV POETRY_VERSION='1.1.3' THEMIS_VERSION=1.5 + +TERRAFORM_VERSION=1.8 diff --git a/with-pr/action.yml b/with-pr/action.yml index d7b00dd..ed360e8 100644 --- a/with-pr/action.yml +++ b/with-pr/action.yml @@ -18,6 +18,12 @@ inputs: description: 'Check tags instead of releases.' default: 'false' required: false + include: + description: 'Regular expression to use only matched versions.' + required: false + exclude: + description: 'Regular expression not to use matched versions.' + required: false tag_prefix: description: 'Tag prefix used for building link in PR description' default: 'v' @@ -28,13 +34,13 @@ inputs: outputs: current: description: 'current version' - value: ${{ steps.depup.outputs.current }} + value: ${{ steps.depup.outputs.current }} latest: description: 'latest version' - value: ${{ steps.depup.outputs.latest }} + value: ${{ steps.depup.outputs.latest }} repo: description: 'target GitHub repository. Same as the repo from input.' - value: ${{ steps.depup.outputs.repo }} + value: ${{ steps.depup.outputs.repo }} runs: using: 'composite' @@ -46,6 +52,8 @@ runs: file: ${{ inputs.file }} version_name: ${{ inputs.version_name }} repo: ${{ inputs.repo }} + include: ${{ inputs.include }} + exclude: ${{ inputs.exclude }} tag: ${{ inputs.tag }} - name: Create Pull Request uses: peter-evans/create-pull-request@v6