Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1 Release - Cleanup, Tests, & Added Options #16

Merged
merged 40 commits into from
Sep 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a147e80
Created test.yml
jtmullen Sep 12, 2021
5848382
Test try one
jtmullen Sep 12, 2021
94e6346
Fix ID
jtmullen Sep 12, 2021
73f383a
Fix bad payload
jtmullen Sep 12, 2021
3743bb3
Fix path to event payload
jtmullen Sep 12, 2021
c9ab530
Fix spacing
jtmullen Sep 12, 2021
c1cd67d
Print directory
jtmullen Sep 12, 2021
5c63cd4
Print directory again
jtmullen Sep 12, 2021
31ebac8
root path?
jtmullen Sep 12, 2021
22f56a7
Print default path
jtmullen Sep 12, 2021
657f20e
reorder
jtmullen Sep 12, 2021
24c58ee
More debug changes'
jtmullen Sep 13, 2021
83ba05c
Fix quotes
jtmullen Sep 13, 2021
dc6a3a7
Fix json
jtmullen Sep 13, 2021
5b123e5
More json fixes'
jtmullen Sep 13, 2021
4399ee5
Fetch depth
jtmullen Sep 13, 2021
61ef989
Change test payload
jtmullen Sep 13, 2021
cd69566
Remove impossible test:
jtmullen Sep 13, 2021
f258105
Fixes in text run
jtmullen Sep 13, 2021
2f69dd4
Debug prinyt
jtmullen Sep 13, 2021
087b89e
more debug
jtmullen Sep 13, 2021
dcb98dc
be on correct hash
jtmullen Sep 13, 2021
8ff664c
New tests!
jtmullen Sep 13, 2021
52e5aaf
json fixes
jtmullen Sep 13, 2021
8c7d544
Fix test cases
jtmullen Sep 13, 2021
204ff0d
Updated test cases
jtmullen Sep 13, 2021
b119138
Change PR base
jtmullen Sep 13, 2021
79102d6
Fix expected output
jtmullen Sep 13, 2021
45abc22
Group outputs, cleanup comments
jtmullen Sep 13, 2021
1bd62bc
Remove unsupported nested group
jtmullen Sep 13, 2021
9d220dc
Fetch Submodule
jtmullen Sep 22, 2021
fe4a09f
Test sub depth pull
jtmullen Sep 22, 2021
96b16f5
Fix id clash
jtmullen Sep 22, 2021
4a290be
Fix input
jtmullen Sep 22, 2021
8d92e14
Fix var name
jtmullen Sep 22, 2021
159ed35
Fix submodule update
jtmullen Sep 22, 2021
858c566
Add test case for sub depth:
jtmullen Sep 22, 2021
6b08ebe
Push correct test
jtmullen Sep 22, 2021
2d16978
Cleanup and readme updates
jtmullen Sep 25, 2021
4b71fe2
Readme fixes
jtmullen Sep 25, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Test try one
  • Loading branch information
jtmullen committed Sep 12, 2021
commit 5848382085f1875f1beb73886efa0af044b9806a
79 changes: 79 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Submodule Action Unit Tests
on: [push, pull_request]

# To test this action we rely on an external repo with commits that have all the scenarios.
# That repo is: https://github.com/jtmullen/submodule-action-test-parent
# These tests do not cover all errors (i.e. some command went wrong)
# The tests do cover all failures (i.e. the submodule state doesn't meet the requirement)

jobs:
run_tests:
runs-on: ubuntu-latest
name: Run All Tests
steps:
- name: Checkout Test Repo
uses: actions/checkout@v2
with:
repository: jtmullen/submodule-action-test-parent
- name: Checkout Action
uses: actions/checkout@v2
with:
path: "action"
# Fail on Unsupported Event Payload
- name: Fail on unsupported Event Payload
uses: ./action/
id: no-submodule
continue-on-error: true
with:
path: "submodule-action-test-submodule"
event_path: "action/test/bad_payload.json"
- name: Verify Fail on unsupported Event Payload
run: test "${{ steps.no-submodule.outputs.fails }}" = "error"
# If the Submodule is not checked out correctly we should fail
- name: Fail Without Submodule
uses: ./action/
id: no-submodule
continue-on-error: true
with:
path: "submodule-action-test-submodule"
event_path: "action/test/new_submodule_event_push.json"
- name: Verify Fail Without Submodule
run: test "${{ steps.no-submodule.outputs.fails }}" = "error"
- name: Checkout Test Repo Submodule
uses: actions/checkout@v2
with:
repository: jtmullen/submodule-action-test-submodule
path: "submodule-action-test-submodule"
fetch-depth: 0
# New Submodules should pass without a progression check
- name: Pass with New Submodule
uses: ./action/
id: new-submodule
with:
path: "submodule-action-test-submodule"
event_path: "action/test/new_submodule_event_push.json"
branch: "main"
- name: Verify Pass with New Submodule
run: test -z "${{ steps.new-submodule.outputs.fails }}"
# New submodule can fail if on wrong branch
- name: Fail New Submodule Wrong Branch
uses: ./action/
id: new-submodule-wrong-branch
continue-on-error: true
with:
path: "submodule-action-test-submodule"
event_path: "action/test/new_submodule_event_push.json"
branch: "fake_branch"
- name: Verify Fail New Submodule Wrong Branch
run: test "${{ steps.no-submodule.outputs.fails }}" = "Submodule submodule-action-test-submodule Hash 803027ba35806133a1a0ecdf8fe89b7e90d1692d is not on branch fake_branch"
# Fail if submodule moves backwards
- name: Fail When Submodule Moves Backwards
uses: ./action/
id: move-backwards
continue-on-error: true
with:
path: "submodule-action-test-submodule"
event_path: "action/test/submodule_moved_backwards.json"
- name: Verify Fail When Submodule Moves Backwards
run: test "${{ steps.no-submodule.outputs.fails }}" = "Submodule submodule-action-test-submodule on 66fe441ec6c2db7565686f303dde85d7eb8ad132 is not an ancestor of that on 1063abeafa3795cfb9f80b0b2241f961d5c8e948"

4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ inputs:
description: "If the submodule should be required to be on the head commit of the specified branch"
required: false
default: ''
event_path:
description: "Override the path to the github event json file. Used for testing."
required: false
default: ''
outputs:
fails:
description: "Cause of failure, if run failed"
Expand Down
33 changes: 21 additions & 12 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

error () {
echo "::set-output name=fails::error"
echo "::error::$1"
exit 1
}
Expand All @@ -12,31 +13,39 @@ newSubmoduleWarning() {
echo "::warning::Submodule $1 does not exist on the base branch/commit; Cannot do progression check for new submodules"
}

REPO=`jq -r ".repository.full_name" "${GITHUB_EVENT_PATH}"`
EVENT_PATH = GITHUB_EVENT_PATH

## Check for test event path
if [[ ! -z "${INPUT_EVENT_PATH}" ]]; then
EVENT_PATH = INPUT_EVENT_PATH
echo "Event Path Overwritten"
fi

REPO=`jq -r ".repository.full_name" "${EVENT_PATH}"`

isPR=false
if [[ $(jq -r ".pull_request.head.ref" "${GITHUB_EVENT_PATH}") != "null" ]]; then
PR=`jq -r ".number" "${GITHUB_EVENT_PATH}"`
PR_BRANCH=`jq -r ".pull_request.head.ref" "${GITHUB_EVENT_PATH}"`
BASE_BRANCH=`jq -r ".pull_request.base.ref" "${GITHUB_EVENT_PATH}"`
USER=`jq -r ".pull_request.user.login" "${GITHUB_EVENT_PATH}"`
if [[ $(jq -r ".pull_request.head.ref" "${EVENT_PATH}") != "null" ]]; then
PR=`jq -r ".number" "${EVENT_PATH}"`
PR_BRANCH=`jq -r ".pull_request.head.ref" "${EVENT_PATH}"`
BASE_BRANCH=`jq -r ".pull_request.base.ref" "${EVENT_PATH}"`
USER=`jq -r ".pull_request.user.login" "${EVENT_PATH}"`
git fetch origin "${PR_BRANCH}" --recurse-submodules=no --depth 1 || error "__Line:${LINENO}__Error: Could not fetch tip of ${PR_BRANCH}"
git fetch origin "${BASE_BRANCH}" --recurse-submodules=no --depth 1 || error "__Line:${LINENO}__Error: Could not fetch tip of ${BASE_BRANCH}"
TO_HASH=`git rev-parse origin/${PR_BRANCH}`
FROM_HASH=`git rev-parse origin/${BASE_BRANCH}`
echo "Run for PR # ${PR} of ${PR_BRANCH} into ${BASE_BRANCH} on ${REPO} by ${USER}"
echo "Hash ${TO_HASH} into ${FROM_HASH}"
isPR=true
elif [[ $(jq -r ".after" "${GITHUB_EVENT_PATH}") != "null" ]]; then
TO_HASH=`jq -r ".after" "${GITHUB_EVENT_PATH}"`
FROM_HASH=`jq -r ".before" "${GITHUB_EVENT_PATH}"`
BRANCH_NAME=`jq -r ".ref" "${GITHUB_EVENT_PATH}"`
elif [[ $(jq -r ".after" "${EVENT_PATH}") != "null" ]]; then
TO_HASH=`jq -r ".after" "${EVENT_PATH}"`
FROM_HASH=`jq -r ".before" "${EVENT_PATH}"`
BRANCH_NAME=`jq -r ".ref" "${EVENT_PATH}"`
BASE_BRANCH="${FROM_HASH}"
PR_BRANCH="${TO_HASH}"
USER=`jq -r ".pusher.name" "${GITHUB_EVENT_PATH}"`
USER=`jq -r ".pusher.name" "${EVENT_PATH}"`
echo "Run for push of ${BRANCH_NAME} from ${FROM_HASH} to ${TO_HASH} on ${REPO} by ${USER}"
else
error "Unknown Github Event Path"
error "Unknown Github Event Payload"
fi

cd "${GITHUB_WORKSPACE}" || error "__Line:${LINENO}__Error: Cannot change directory to Github Workspace"
Expand Down
10 changes: 10 additions & 0 deletions test/bad_payload.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"before": "66fe441ec6c2db7565686f303dde85d7eb8ad132",
"pusher": {
"name": "jtmullen"
},
"ref": "refs/heads/main",
"repository": {
"full_name": "jtmullen/submodule-action-test-parent",
},
}
11 changes: 11 additions & 0 deletions test/new_submodule_event_push.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"after": "7c0243f036a44489eddc0ac98fee2d11cbecc4b2",
"before": "3da1cd0f9ed5b5e60e4f3e58672308dfe657cb8c",
"pusher": {
"name": "jtmullen"
},
"ref": "refs/heads/main",
"repository": {
"full_name": "jtmullen/submodule-action-test-parent",
},
}
11 changes: 11 additions & 0 deletions test/submodule_moved_backwards.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"after": "1063abeafa3795cfb9f80b0b2241f961d5c8e948",
"before": "66fe441ec6c2db7565686f303dde85d7eb8ad132",
"pusher": {
"name": "jtmullen"
},
"ref": "refs/heads/main",
"repository": {
"full_name": "jtmullen/submodule-action-test-parent",
},
}