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

ARCH-1690 - Adding a test job to the build-and-review-pr.yml #19

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 34 additions & 0 deletions .github/workflows/build-and-review-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,37 @@ 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: '' # TODO: Update if this action has a build step.

test:
runs-on: ubuntu-latest
steps:
#--------------------------------------
# Setup
#--------------------------------------
- uses: actions/checkout@v3
# TODO: add any additional steps needed to setup the test scenarios

# TODO: Replace with the scenarios needed to test this action

#--------------------------------------
# SCENARIO 1
#--------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""

- name: When the repo is 'im-open/composite-action-template'
id: repo-check
run: |
if [ "${{ github.repository }}" != "im-open/composite-action-template" ]; then
exit 1
else
echo "SUCCESS=true" >> "$GITHUB_OUTPUT"
fi

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

- name: And the SUCCESS output should be true
if: always()
run: ./test/assert-values-match.sh --name "SUCCESS output" --expected "true" --actual "${{ steps.repo-check.outputs.SUCCESS }}"
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This template can be used to quickly start a new custom composite-run-steps acti
- [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 @@ -93,6 +94,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 @@ -118,6 +120,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. When a PR comes from a branch, there should not be any issues running the tests. When a PR comes from a fork, tests may not have the required permissions or access to run since the `GITHUB_TOKEN` only has `read` access set for all scopes. Also, forks cannot access other secrets in the repository. In these scenarios, a fork may need to be merged into an intermediate branch by the repository owners to ensure the tests run successfully prior to merging to the default branch.

## 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
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