diff --git a/.github/workflows/build-and-review-pr.yml b/.github/workflows/build-and-review-pr.yml index 7505959..54dbc97 100644 --- a/.github/workflows/build-and-review-pr.yml +++ b/.github/workflows/build-and-review-pr.yml @@ -51,14 +51,49 @@ jobs: # Files do not need to be explicitly provided here if they fall under one of the dirs in dirs-with-code. # The format of this input is a comma-separated string. # ** This value must match the same files-with-code argument specified in increment-version-on-merge.yml. - files-with-code: 'action.yml,package.json,package-lock.json' # TODO: Update if there are additional files or scripts. + files-with-code: 'action.yml,package.json,package-lock.json' # TODO: Update if there are additional files or scripts. # The directories that contain source code for the action. Only dirs with files that affect the action's # execution should be included like src or dist. Do not include dirs like .github or node_modules. # The format of this input is a comma-separated string. # ** This value must match the same dirs-with-code argument specified in increment-version-on-merge.yml. - dirs-with-code: 'src,dist' # TODO: Update if there are additional directories with code for the action. + dirs-with-code: 'src,dist' # TODO: Update if there are additional directories with code for the action. # 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: 'npm run build' # TODO: Update if a different command is used to build/recompile/format the action + + 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/javascript-action-template' + if: always() + id: repo-check + run: | + if [ "${{ github.repository }}" != "im-open/javascript-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 }}" diff --git a/README.md b/README.md index 5f49710..a8a388e 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ This template can be used to quickly start a new custom js action repository. C - [Source Code Changes](#source-code-changes) - [Recompiling Manually](#recompiling-manually) - [Updating the README.md](#updating-the-readmemd) + - [Tests](#tests) - [Code of Conduct](#code-of-conduct) - [License](#license) @@ -101,6 +102,7 @@ When creating PRs, please review the following guidelines: - [ ] At least one of the commit messages contains the appropriate `+semver:` keywords listed under [Incrementing the Version] for major and minor increments. - [ ] The action has been recompiled. See [Recompiling Manually] for details. - [ ] 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 @@ -135,6 +137,10 @@ npm run build 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). diff --git a/test/assert-values-match.sh b/test/assert-values-match.sh new file mode 100755 index 0000000..147b626 --- /dev/null +++ b/test/assert-values-match.sh @@ -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 \ No newline at end of file