Skip to content

Commit

Permalink
Lint and Test on PR (#24)
Browse files Browse the repository at this point in the history
* Lint and Test on PR

* Adjust readme example

* change this back to on push

* move back to PR with some handling for it

* commit all

* diff the two files

* fix the git diff command

* store both things in the diff_output

* be quiet about the fetch

* update echo, we're not committing anything

* add a note to our future selves

* file is echoed as part of the diff

---------

Co-authored-by: Chris Reynolds <chris@jazzsequence.com>
  • Loading branch information
pwtyler and jazzsequence committed Apr 16, 2024
1 parent 744c38a commit 834f111
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/lint.yml

This file was deleted.

19 changes: 16 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
name: Test
on: [push]
name: Lint & Test
on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review

jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Shellcheck
run: shellcheck bin/*.sh
test:
runs-on: ubuntu-latest
name: Test
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ./
with:
dependencies-yml: ./fixtures/dependencies.yml
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@ name: Package Updater
on:
schedule:
- cron: '0 * * * *'

permissions:
contents: write
pull-requests: write

jobs:
updater:
runs-on: ubuntu-latest
name: Run Package Updater
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: pantheon-systems/action-package-updater@v1
with:
dependencies-yml: ./dependencies.yml
Expand Down
20 changes: 17 additions & 3 deletions bin/dependency-check-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,28 @@ ${PR_NOTE}"
echo
done
if [[ "${DRY_RUN}" == "true" ]]; then
local diff_output=""
echo "Dry run requested...checking the diff...🤔"
BRANCH="${DEFAULT_BRANCH}"
if [[ "${ACTIVE_BRANCH}" != "${BRANCH}" ]]; then
echo "Default branch is ${BRANCH}, but active branch is ${ACTIVE_BRANCH}. We'll check out ${ACTIVE_BRANCH} instead."
BRANCH="${ACTIVE_BRANCH}"
if [[ "${ACTIVE_BRANCH}" =~ refs/pull/[0-9]+/merge ]]; then
echo "Active branch is a PR branch."
git fetch origin "${DEFAULT_BRANCH}" > /dev/null 2>&1
# There are only two files tracked. If we start tracking more, we'll need to update this.
files_to_compare=("${OUTPUT_FILE}" "${DEPENDENCIES_YML}")
echo "Comparing changes between ${BRANCH} and ${ACTIVE_BRANCH}"
for file in "${files_to_compare[@]}"; do
diff_output+=$(git diff --color=always -U0 "origin/${DEFAULT_BRANCH}:${file}" "${file}")$'\n\n'
done
else
echo "Default branch is ${BRANCH}, but active branch is ${ACTIVE_BRANCH}. We'll check out ${ACTIVE_BRANCH} instead."
BRANCH="${ACTIVE_BRANCH}"
fi
fi
# If we're doing a dry-run, let's output a diff so we can see that it did something.
if git rev-parse --verify HEAD >/dev/null 2>&1; then
if [[ -n "${diff_output}" ]]; then
echo "$diff_output"
elif git rev-parse --verify HEAD >/dev/null 2>&1; then
diff_output=$(git diff --color=always -U0 "${BRANCH}"...HEAD)
echo "$diff_output"
else
Expand Down

0 comments on commit 834f111

Please sign in to comment.