Skip to content

Commit

Permalink
feat: action outputs (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
AuHau authored Dec 3, 2021
1 parent b56dfed commit 0bd77d5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ jobs:
- run: "npm ci"
- run: "npm run build"
- uses: ./
id: run
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ACTIONS_STEP_DEBUG: true
with:
commit-message: "Just testing [skip ci]"
- if: ${{ steps.run.outputs.result != 'updated' || steps.run.outputs.pull-request-number > 0 }}
run: 'echo "Output of action is not as expected" && exit 1'

createNewPullRequest:
name: "[TEST] Create new pull request"
Expand All @@ -39,6 +42,7 @@ jobs:
- run: "npm ci"
- run: "npm run build"
- uses: ./
id: run
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ACTIONS_STEP_DEBUG: true
Expand All @@ -53,6 +57,10 @@ jobs:
- run: "git push https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git :test-create-new-pull-request"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- if: ${{ steps.run.outputs.result != 'created' }}
run: 'echo "result output is \"${{ steps.run.outputs.result }}\" but expected \"created\"" && exit 1'
- if: ${{ steps.run.outputs.pull-request-number > 0 }}
run: 'echo "pull-request-number output is \"${{ steps.run.outputs.pull-request-number }}\" but expected a number" && exit 1'

multipleCommits:
name: "[TEST] Create multiple commits"
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ If there are changes, it does the following
4. Pushes the local changes to remote using the branch configured in the `branch` input.
5. Creates a pull request using the `title` and `body` inputs. If a pull request exists for the branch, it's checked out locally, rebased with `-XTheirs` and pushed with `--force` to update the pull request with the new changes.

The actions outputs following properties:

- `pull-request-number` - number of created/updated PR. Not set if result is `unchanged`.
- `result` - `created`, `updated` or `unchanged` based if the PR was created, updated or if there were no local changes.

The action is written in JavaScript. [Learn how to create your own](https://help.github.com/en/articles/creating-a-javascript-action).

## Who is using it
Expand Down
8 changes: 7 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ inputs:
description: "Pull Request body"
required: true
default: |
This pull request has been created by the ["Create or Update Pull Request" action](https://github.com/gr2m/create-or-update-pull-request-action#readme).
This pull request has been created by the ["Create or Update Pull Request" action](https://github.com/gr2m/create-or-update-pull-request-action#readme).
You can set a custom pull request title, body, branch and commit messages, see [Usage](https://github.com/gr2m/create-or-update-pull-request-action#usage).
branch:
Expand Down Expand Up @@ -40,6 +40,12 @@ inputs:
description: "Enable auto merge for pull request. Requires auto merging to be enabled in repository settings"
required: false

outputs:
pull-request-number:
description: "Number of the created/updated pull request"
result:
description: "'updated', 'created', 'unchanged' based if the PR was created, updated or nothing happened"

runs:
using: "node12"
main: "dist/index.js"
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ async function main() {
} else {
core.info("No local changes");
}

core.setOutput("result", "unchanged")
process.exit(0); // there is currently no neutral exit code
}

Expand Down Expand Up @@ -150,8 +152,12 @@ async function main() {
});

if (data.total_count > 0) {
const prInfo = data.items[0]; // Assuming there is only one PR for given branch

core.setOutput(`pull-request-number`, prInfo.number);
core.setOutput(`result`, `updated`);
core.info(
`Existing pull request for branch "${inputs.branch}" updated: ${data.items.html_url}`
`Existing pull request for branch "${inputs.branch}" updated: ${prInfo.html_url}`
);
return;
}
Expand All @@ -171,6 +177,9 @@ async function main() {

core.info(`Pull request created: ${html_url} (#${number})`);

core.setOutput(`pull-request-number`, number);
core.setOutput(`result`, `created`);

if (inputs.labels) {
core.debug(`Adding labels: ${inputs.labels}`);
const labels = inputs.labels.trim().split(/\s*,\s*/);
Expand Down

0 comments on commit 0bd77d5

Please sign in to comment.