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

feat: action outputs #352

Merged
merged 5 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 6 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.outpus.result != 'updated' || steps.run.outpus.pull-request-number > 0 }}
AuHau marked this conversation as resolved.
Show resolved Hide resolved
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,8 @@ 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.outpus.result != 'created' || steps.run.outpus.pull-request-number > 0 }}
run: 'echo "Output of action is not as expected" && exit 1'
AuHau marked this conversation as resolved.
Show resolved Hide resolved

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.

AuHau marked this conversation as resolved.
Show resolved Hide resolved
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