Skip to content

Commit

Permalink
ARCH-1919 - Transfer to Infra-Purple
Browse files Browse the repository at this point in the history
- Update CODEOWNERS
- Add tests to build-and-review-pr.yml
  • Loading branch information
danielle-casella-adams committed Sep 20, 2023
1 parent 0b6762d commit 4104062
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @im-open/swat
* @im-open/infra-purple
150 changes: 150 additions & 0 deletions .github/workflows/build-and-review-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,153 @@ jobs:
# The npm script to run to build the action. This is typically 'npm run build' if the
# action needs to be compiled. For composite-run-steps actions this is typically empty.
build-command: ''

test:
runs-on: ubuntu-latest

env:
# NOTE: These three releases have been created in this action's repository to test with.
# If they are removed or updated, these tests will fail.
EXISTING_BRANCH: 'main'
EXISTING_TAG: 'v1.2.1'
EXISTING_SHA: 'd1646b13d2370437f7ca85233d340cb2e15b74c7'
NONEXISTENT_REF: 'v304.973.444'

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

#--------------------------------------
# EXISTING BRANCH REF
#--------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""

- name: When validating an existing branch (${{ env.EXISTING_BRANCH}})
uses: ./
if: always()
id: existing-branch
with:
branch-tag-sha: ${{ env.EXISTING_BRANCH }}
throw-errors: true

- name: Then the outcome should be success
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.existing-branch.outcome }}"

- name: And the REF_EXISTS output should be true
if: always()
run: ./test/assert-values-match.sh --name "REF_EXISTS" --expected "true" --actual "${{ steps.existing-branch.outputs.REF_EXISTS }}"

- name: And the REF_TYPE output should be branch
if: always()
run: ./test/assert-values-match.sh --name "REF_TYPE" --expected "branch" --actual "${{ steps.existing-branch.outputs.REF_TYPE }}"


#--------------------------------------
# EXISTING TAG REF
#--------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""

- name: When validating an existing tag (${{ env.EXISTING_TAG}})
uses: ./
if: always()
id: existing-tag
with:
branch-tag-sha: ${{ env.EXISTING_TAG }}
throw-errors: true

- name: Then the outcome should be success
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.existing-tag.outcome }}"

- name: And the REF_EXISTS output should be true
if: always()
run: ./test/assert-values-match.sh --name "REF_EXISTS" --expected "true" --actual "${{ steps.existing-tag.outputs.REF_EXISTS }}"

- name: And the REF_TYPE output should be tag
if: always()
run: ./test/assert-values-match.sh --name "REF_TYPE" --expected "tag" --actual "${{ steps.existing-tag.outputs.REF_TYPE }}"

#--------------------------------------
# EXISTING SHA REF
#--------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""

- name: When validating an existing sha (${{ env.EXISTING_SHA}})
uses: ./
if: always()
id: existing-sha
with:
branch-tag-sha: ${{ env.EXISTING_SHA }}
throw-errors: true

- name: Then the outcome should be success
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.existing-sha.outcome }}"

- name: And the REF_EXISTS output should be true
if: always()
run: ./test/assert-values-match.sh --name "REF_EXISTS" --expected "true" --actual "${{ steps.existing-sha.outputs.REF_EXISTS }}"

- name: And the REF_TYPE output should be sha
if: always()
run: ./test/assert-values-match.sh --name "REF_TYPE" --expected "sha" --actual "${{ steps.existing-sha.outputs.REF_TYPE }}"

#-------------------------------------------------
# REF DOES NOT EXIST WITH THROW-ERROR SET TO FALSE
#-------------------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""

- name: When validating an non-existent ref (${{ env.NONEXISTENT_REF}}) and throw-errors is false
uses: ./
if: always()
id: nonexistent-ref-no-errors
with:
branch-tag-sha: ${{ env.NONEXISTENT_REF }}
throw-errors: false

- name: Then the outcome should be success
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.nonexistent-ref-no-errors.outcome }}"

- name: And the REF_EXISTS output should be false
if: always()
run: ./test/assert-values-match.sh --name "REF_EXISTS" --expected "false" --actual "${{ steps.nonexistent-ref-no-errors.outputs.REF_EXISTS }}"

- name: And the REF_TYPE output should be unknown
if: always()
run: ./test/assert-values-match.sh --name "REF_TYPE" --expected "unknown" --actual "${{ steps.nonexistent-ref-no-errors.outputs.REF_TYPE }}"

#-------------------------------------------------
# REF DOES NOT EXIST WITH THROW-ERROR SET TO TRUE
#-------------------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""

- name: When validating an non-existent ref (${{ env.NONEXISTENT_REF}}) and throw-errors is true
uses: ./
if: always()
id: nonexistent-ref-with-errors
with:
branch-tag-sha: ${{ env.NONEXISTENT_REF }}
throw-errors: true

- name: Then the outcome should be failure
if: always()
run: ./test/assert-values-match.sh --name "step outcome" --expected "failure" --actual "${{ steps.nonexistent-ref-with-errors.outcome }}"

- name: And the REF_EXISTS output should be false
if: always()
run: ./test/assert-values-match.sh --name "REF_EXISTS" --expected "false" --actual "${{ steps.nonexistent-ref-with-errors.outputs.REF_EXISTS }}"

- name: And the REF_TYPE output should be unknown
if: always()
run: ./test/assert-values-match.sh --name "REF_TYPE" --expected "unknown" --actual "${{ steps.nonexistent-ref-with-errors.outputs.REF_TYPE }}"

- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""
37 changes: 37 additions & 0 deletions test/assert-values-match.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

name=''
expectedValue=''
actualValue=''

for arg in "$@"; do
case $arg in
--name)
name=$2
shift # Remove argument --name from `$@`
shift # Remove argument value from `$@`
;;
--expected)
expectedValue=$2
shift # Remove argument --expected from `$@`
shift # Remove argument value from `$@`
;;
--actual)
actualValue=$2
shift # Remove argument --actual from `$@`
shift # Remove argument value from `$@`
;;

esac
done

echo "
Expected $name: '$expectedValue'"
echo "Actual $name: '$actualValue'"

if [ "$expectedValue" != "$actualValue" ]; then
echo "The expected $name does not match the actual $name."
exit 1
else
echo "The expected and actual $name values match."
fi

0 comments on commit 4104062

Please sign in to comment.