Skip to content

Commit

Permalink
ARCH-1919 - Transfer to Infra-Purple (#14)
Browse files Browse the repository at this point in the history
* ARCH-1919 - Transfer to Infra-Purple

- Update CODEOWNERS
- Add tests to build-and-review-pr.yml

* ARCH-1919 - Updates for consistency

* ARCH-1919 - Address tests and forks in readme
  • Loading branch information
danielle-casella-adams authored Oct 17, 2023
1 parent 7793ccf commit 614e854
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 6 deletions.
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
116 changes: 116 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,119 @@ 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: The unreachable tag has been created to be unreachable from main. If it is removed
# these tests may start to fail.
UNREACHABLE_BRANCH: 'unreachable-branch'
UNREACHABLE_TAG: 'v0.0.0'
REACHABLE_TAG: 'v1.1.2'

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

#--------------------------------------
# TAG IS REACHABLE FROM MAIN
#--------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""

- name: When a tag is reachable from main
# You may also reference just the major or major.minor version
uses: ./
if: always()
id: reachable
with:
tag: ${{ env.REACHABLE_TAG }}
default-branch: 'main'
error-if-not-reachable: true

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

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

#-----------------------------------------------------------------
# TAG IS UNREACHABLE FROM MAIN AND ERROR-IF-NOT-REACHABLE IS FALSE
#-----------------------------------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""

- name: When a tag is unreachable from main and error-if-not-reachable is false
# You may also reference just the major or major.minor version
uses: ./
if: always()
id: unreachable-no-error
with:
tag: ${{ env.UNREACHABLE_TAG }}
default-branch: 'main'
error-if-not-reachable: false

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

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

#-----------------------------------------------------------------
# TAG IS UNREACHABLE FROM MAIN AND ERROR-IF-NOT-REACHABLE IS TRUE
#-----------------------------------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""

- name: When a tag is unreachable from main and error-if-not-reachable is true
# You may also reference just the major or major.minor version
uses: ./
if: always()
continue-on-error: true # This is needed because we expect the step to fail. It needs to "pass" in order for the test job to succeed.
id: unreachable-with-error
with:
tag: ${{ env.UNREACHABLE_TAG }}
default-branch: 'main'
error-if-not-reachable: true

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

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


#-----------------------------------------------------------------
# REF IS PROVIDED
#-----------------------------------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""

- name: When a ref is provided
# You may also reference just the major or major.minor version
uses: ./
if: always()
continue-on-error: true # This is needed because we expect the step to fail. It needs to "pass" in order for the test job to succeed.
id: ref
with:
tag: ${{ env.REACHABLE_TAG }}
default-branch: 'main'
ref: ${{ env.UNREACHABLE_BRANCH }} # The action should switch back to this ref
error-if-not-reachable: true

- name: Then the action should switch back to that ref
if: always()
run: |
currentBranch=$(git rev-parse --abbrev-ref HEAD)
./test/assert-values-match.sh --name "current branch" --expected "${{ env.UNREACHABLE_BRANCH }}" --actual $currentBranch
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# is-tag-reachable-from-default-branch

This action takes in a tag and determines if it is reachable from the default branch. This action should be used in conjunction with the `actions/checkout` action where a fetch-depth has been set so the action has access to tags and history.
This action takes in a tag and determines if it is reachable from the default branch. This action should be used in conjunction with the `actions/checkout` action where the `fetch-depth` arg has been set so the action has access to tags and history.

When this executes it will:

Expand All @@ -24,6 +24,7 @@ If you are working on something other than the default branch, it may be best to
- [Incrementing the Version](#incrementing-the-version)
- [Source Code Changes](#source-code-changes)
- [Updating the README.md](#updating-the-readmemd)
- [Tests](#tests)
- [Code of Conduct](#code-of-conduct)
- [License](#license)

Expand Down Expand Up @@ -54,7 +55,7 @@ jobs:

- name: Check if tag is reachable by main
# You may also reference just the major or major.minor version
uses: im-open/is-tag-reachable-from-default-branch@v1.1.2
uses: im-open/is-tag-reachable-from-default-branch@v1.1.3
with:
tag: 'latest'

Expand All @@ -65,7 +66,7 @@ jobs:
- uses: actions/checkout@v3

- name: Check if tag is reachable by main
uses: im-open/is-tag-reachable-from-default-branch@v1.1.2
uses: im-open/is-tag-reachable-from-default-branch@v1.1.3
with:
tag: 'latest'
ref: ${{ github.ref }}
Expand All @@ -81,7 +82,7 @@ jobs:

- name: Check if tag is reachable by master
id: tag-check
uses: im-open/is-tag-reachable-from-default-branch@v1.1.2
uses: im-open/is-tag-reachable-from-default-branch@v1.1.3
with:
tag: 'latest' # The tag to check
error-if-not-reachable: false # Don't throw an error if the tag is not reachable
Expand Down Expand Up @@ -113,6 +114,7 @@ When creating PRs, please review the following guidelines:
- [ ] The action code does not contain sensitive information.
- [ ] At least one of the commit messages contains the appropriate `+semver:` keywords listed under [Incrementing the Version] for major and minor increments.
- [ ] The README.md has been updated with the latest version of the action. See [Updating the README.md] for details.
- [ ] Any tests in the [build-and-review-pr] workflow are passing

### Incrementing the Version

Expand All @@ -138,6 +140,10 @@ If a PR consists solely of non-source code changes like changes to the `README.m

If changes are made to the action's [source code], the [usage examples] section of this file should be updated with the next version of the action. Each instance of this action should be updated. This helps users know what the latest tag is without having to navigate to the Tags page of the repository. See [Incrementing the Version] for details on how to determine what the next version will be or consult the first workflow run for the PR which will also calculate the next version.

### Tests

The build and review PR workflow includes tests which are linked to a status check. That status check needs to succeed before a PR is merged to the default branch. The tests do not need special permissions, so they should succeed whether they come from a branch or a fork.

## Code of Conduct

This project has adopted the [im-open's Code of Conduct](https://github.com/im-open/.github/blob/main/CODE_OF_CONDUCT.md).
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ inputs:
required: true
default: 'main'
ref:
description: 'The default branch for the repository. Defaults to main.'
description: 'Required when a `ref` arg was used with `actions/checkout` or if a non-default branch was selected when starting the workflow. Specify the same ref here so the action can return the repository to that ref.'
required: false
error-if-not-reachable:
description: 'Throw an error if the tag is not reachable from the default branch'
Expand Down
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 614e854

Please sign in to comment.