Skip to content

Commit

Permalink
Support including/excluding specific version patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
nasa9084 committed Jul 3, 2024
1 parent 07a2fe6 commit f1460d6
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 3 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/depup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
18 changes: 18 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -50,6 +67,7 @@ set_output() {
LATEST_VERSION="$(\
list_versions | \
grep -oP '\d+(\.\d+)+(-[^'\''\"\s]*)?$'| \
filter_versions | \
sort --version-sort --reverse | \
head -n1 \
)"
Expand Down
2 changes: 2 additions & 0 deletions testdata/testfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ POETRY_VERSION="1.1.3"
ENV POETRY_VERSION='1.1.3'

THEMIS_VERSION=1.5

TERRAFORM_VERSION=1.8
14 changes: 11 additions & 3 deletions with-pr/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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
Expand Down

0 comments on commit f1460d6

Please sign in to comment.