Skip to content

Commit c54e156

Browse files
filter files by regex
1 parent 94c689a commit c54e156

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

.github/workflows/repository_latest_added_files.yml

+9-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ on:
2121
type: string
2222
required: true
2323
time:
24-
description: 'UTC Time (HH:MM:SS)'
24+
description: 'UTC Time (HH:MM:SS) (minutes and seconds optional)'
2525
type: string
2626
required: true
2727
environment:
@@ -32,6 +32,11 @@ on:
3232
- staging
3333
- production
3434
default: 'staging'
35+
filter:
36+
description: 'filter by regex in staging'
37+
type: string
38+
default: '.*'
39+
required: false
3540

3641
jobs:
3742
list-files:
@@ -43,12 +48,9 @@ jobs:
4348
set -e
4449
datetime="${{ github.event.inputs.date_year }}-${{ github.event.inputs.date_month }}-${{ github.event.inputs.date_day }} ${{ github.event.inputs.time }}"
4550
# Regular expression to match the format YYYY-MM-DD HH:MM:SS
46-
regex="^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$"
51+
regex="^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}(:[0-9]{2}){0,2}$"
4752
48-
if [[ $datetime =~ $regex ]]; then
49-
# Use date command to check if it's a valid date
50-
date -d "$datetime" >/dev/null 2>&1 || exit 1
51-
else
53+
if [[ ! $datetime =~ $regex ]]; then
5254
exit 1
5355
fi
5456
echo "DATE_TIME=$datetime" >> $GITHUB_ENV
@@ -66,7 +68,7 @@ jobs:
6668
- name: List files created before and after datetime in Staging S3
6769
if: ${{ github.event.inputs.environment == 'staging' }}
6870
run: |
69-
TZ="UTC" aws s3 ls s3://nr-downloads-ohai-staging/infrastructure_agent/ --recursive | sort | grep --color -m 1 -C ${{ github.event.inputs.count }} "^${{ env.DATE_TIME }}"
71+
TZ="UTC" aws s3 ls s3://nr-downloads-ohai-staging/infrastructure_agent/ --recursive | sort | grep -E "${{ github.event.inputs.filter }}" | grep --color -m 1 -C ${{ github.event.inputs.count }} "^${{ env.DATE_TIME }}"
7072
env:
7173
AWS_ACCESS_KEY_ID: ${{ secrets.OHAI_AWS_ACCESS_KEY_ID_STAGING }}
7274
AWS_SECRET_ACCESS_KEY: ${{ secrets.OHAI_AWS_SECRET_ACCESS_KEY_STAGING }}

0 commit comments

Comments
 (0)