Skip to content

Commit

Permalink
feat: make workflow compatible with old action
Browse files Browse the repository at this point in the history
- remove deprecation warnings for nodejs
- add new output `pr_created`
- add error output logs
- fail on error
  • Loading branch information
stevie- authored Feb 5, 2024
2 parents d1a9410 + 659fad8 commit 16eed67
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 77 deletions.
19 changes: 6 additions & 13 deletions .github/workflows/macos_action_test.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
name: Action test on MacOS

on:
schedule:
- cron: "0 4 * * MON-FRI" # Runs at 04:00 UTC
push:
pull_request:
branches: [main]
workflow_dispatch:

jobs:
macos-min:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: GuillaumeFalourd/pull-request-action@main
with:
source_branch: "main"
destination_branch: "test-macos-min"
- uses: actions/checkout@v4
- uses: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

macos-max:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: GuillaumeFalourd/pull-request-action@main
- uses: actions/checkout@v4
- uses: ./
with:
source_branch: "main"
destination_branch: "test-macos-max"
pr_title: "Pulling ${{ github.ref }} into main"
pr_body: "An automated PR"
pr_reviewer: "GuillaumeFalourd"
Expand All @@ -36,4 +29,4 @@ jobs:
pr_draft: true
pr_allow_empty: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25 changes: 11 additions & 14 deletions .github/workflows/ubuntu_action_test.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
name: Action test on Ubuntu

on:
schedule:
- cron: "0 2 * * MON-FRI" # Runs at 02:00 UTC
push:
pull_request:
branches: [main]
workflow_dispatch:

jobs:
ubuntu-min:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: GuillaumeFalourd/pull-request-action@main
with:
source_branch: "main"
destination_branch: "test-ubuntu-min"
- uses: actions/checkout@v4
- uses: ./
id: pr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: echo -e "Output of pr job is:\n${{ tojson(steps.pr.outputs) }}"

ubuntu-max:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: GuillaumeFalourd/pull-request-action@main
- uses: actions/checkout@v4
- uses: ./
id: pr
with:
source_branch: "main"
destination_branch: "test-ubuntu-max"
pr_title: "Pulling ${{ github.ref }} into main"
pr_title: "Pulling ${{ github.ref_name }} into main"
pr_body: "An automated PR"
pr_reviewer: "GuillaumeFalourd"
pr_assignee: "GuillaumeFalourd"
Expand All @@ -36,4 +32,5 @@ jobs:
pr_draft: true
pr_allow_empty: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: echo -e "Output of pr job is:\n${{ tojson(steps.pr.outputs) }}"
19 changes: 6 additions & 13 deletions .github/workflows/windows_action_test.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
name: Action test on Windows

on:
schedule:
- cron: "0 6 * * MON-FRI" # Runs at 06:00 UTC
push:
pull_request:
branches: [main]
workflow_dispatch:

jobs:
windows-min:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: GuillaumeFalourd/pull-request-action@main
with:
source_branch: "main"
destination_branch: "test-windows-min"
- uses: actions/checkout@v4
- uses: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

windows-max:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: GuillaumeFalourd/pull-request-action@main
- uses: actions/checkout@v4
- uses: ./
with:
source_branch: "main"
destination_branch: "test-windows-max"
pr_title: "Pulling ${{ github.ref }} into main"
pr_body: "An automated PR"
pr_reviewer: "GuillaumeFalourd"
Expand All @@ -36,4 +29,4 @@ jobs:
pr_draft: true
pr_allow_empty: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# Pull Request Action

[![Action test on Ubuntu](https://github.com/GuillaumeFalourd/pull-request-action/actions/workflows/ubuntu_action_test.yml/badge.svg)](https://github.com/GuillaumeFalourd/pull-request-action/actions/workflows/ubuntu_action_test.yml) [![Action test on MacOS](https://github.com/GuillaumeFalourd/pull-request-action/actions/workflows/macos_action_test.yml/badge.svg)](https://github.com/GuillaumeFalourd/pull-request-action/actions/workflows/macos_action_test.yml) [![Action test on Windows](https://github.com/GuillaumeFalourd/pull-request-action/actions/workflows/windows_action_test.yml/badge.svg)](https://github.com/GuillaumeFalourd/pull-request-action/actions/workflows/windows_action_test.yml)
[![Action test on Ubuntu](https://github.com/datadrivers/pull-request-action/actions/workflows/ubuntu_action_test.yml/badge.svg)](https://github.com/datadrivers/pull-request-action/actions/workflows/ubuntu_action_test.yml) [![Action test on MacOS](https://github.com/datadrivers/pull-request-action/actions/workflows/macos_action_test.yml/badge.svg)](https://github.com/datadrivers/pull-request-action/actions/workflows/macos_action_test.yml) [![Action test on Windows](https://github.com/datadrivers/pull-request-action/actions/workflows/windows_action_test.yml/badge.svg)](https://github.com/datadrivers/pull-request-action/actions/workflows/windows_action_test.yml)

![](https://user-images.githubusercontent.com/22433243/157692326-2e75f43d-e563-4fa9-8947-67c06e4e469f.png)

☞ Github Actions to create pull request using Github CLI ⤵️
☞ Github Actions to create pull request using Github CLI ⤵️

_**Note**: This action is supported on **all runners** operating systems (`ubuntu`, `macos`, `windows`)_

_Inspired from [https://github.com/repo-sync/pull-request](https://github.com/repo-sync/pull-request)_

_Original Code from [github.com/GuillaumeFalourd/pull-request-action](https://github.com/GuillaumeFalourd/pull-request-action)_

## 📝 Features

- Create pull requests
Expand All @@ -31,7 +33,7 @@ _Inspired from [https://github.com/repo-sync/pull-request](https://github.com/re
### Minimum configurations

```yaml
- uses: GuillaumeFalourd/pull-request-action@v1
- uses: datadrivers/pull-request-action@v2
with:
destination_branch: "main"
env:
Expand All @@ -41,7 +43,7 @@ _Inspired from [https://github.com/repo-sync/pull-request](https://github.com/re
### Full configurations
```yaml
- uses: GuillaumeFalourd/pull-request-action@v1
- uses: datadrivers/pull-request-action@v2
with:
source_branch: "main" # If blank, default: triggered branch
destination_branch: "feature" # If blank, default: main
Expand All @@ -59,16 +61,16 @@ _Inspired from [https://github.com/repo-sync/pull-request](https://github.com/re
## 🤝 Contributing
☞ If you're interested in contributing to this repository, please follow the [guidelines](https://github.com/GuillaumeFalourd/pull-request-action/blob/main/CONTRIBUTING.md)
☞ If you're interested in contributing to this repository, please follow the [guidelines](https://github.com/datadrivers/pull-request-action/blob/main/CONTRIBUTING.md)
## 🏅 Licensed
☞ This repository uses the [Apache License 2.0](https://github.com/GuillaumeFalourd/pull-request-action/blob/main/LICENSE)
☞ This repository uses the [Apache License 2.0](https://github.com/datadrivers/pull-request-action/blob/main/LICENSE)
<!-- ### Contribuidores
<a href="https://github.com/GuillaumeFalourd/pull-request-action/graphs/contributors">
<img src="https://contrib.rocks/image?repo=GuillaumeFalourd/pull-request-action" />
<a href="https://github.com/datadrivers/pull-request-action/graphs/contributors">
<img src="https://contrib.rocks/image?repo=datadrivers/pull-request-action" />
</a>
(Criado com [contributors-img](https://contrib.rocks)) -->
79 changes: 50 additions & 29 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: Pull Request Action (Github CLI)

description: Github Actions to create pull request (all os supported) using Github CLI ⤵️
description: Github Actions to create pull request (all os supported) using Github CLI ⤵️

inputs:
source_branch:
description: Branch name to pull from, default is triggered branch
required: false
destination_branch:
description: Branch name to sync to in this repo, default is master
description: Branch name to sync to in this repo, default is main
required: false
default: master
default: main
pr_title:
description: Pull request title
required: false
Expand Down Expand Up @@ -38,15 +38,22 @@ inputs:
outputs:
pr_url:
description: 'Pull request URL'
value: ${{ steps.pr-creation.outputs.pr_url }}
pr_number:
description: 'Pull request number'
value: ${{ steps.pr-creation.outputs.pr_number }}
has_changed_files:
description: 'Boolean string indicating whether any file has been changed'
value: ${{ steps.pr-creation.outputs.has_changed_files }}
pr_created:
description: 'Boolean string indicating whether a PR was created'
value: ${{ steps.pr-creation.outputs.pr_created }}

runs:
using: "composite"
steps:
- name: Create Pull Request ⤵️
- name: Create Pull Request ⤵️
id: pr-creation
run: |
set -e
set -o pipefail
Expand All @@ -65,6 +72,8 @@ runs:
else
DESTINATION_BRANCH="main"
fi
# init pr_created bool
echo "pr_created=false" >> "$GITHUB_OUTPUT"
# Github actions no longer auto set the username and GITHUB_TOKEN
git remote set-url origin "https://$GITHUB_ACTOR:$GITHUB_TOKEN@${GITHUB_SERVER_URL#https://}/$GITHUB_REPOSITORY"
Expand All @@ -90,58 +99,70 @@ runs:
# Workaround for `hub` auth error https://github.com/github/hub/issues/2149#issuecomment-513214342
export GITHUB_USER="$GITHUB_ACTOR"
COMMAND="gh pr create --base $DESTINATION_BRANCH --head $SOURCE_BRANCH --no-maintainer-edit"
# set -x
declare -a COMMAND
COMMAND+=(gh pr create --base $DESTINATION_BRANCH --head $SOURCE_BRANCH --no-maintainer-edit)
if [[ ! -z "${{ inputs.pr_title }}" ]]; then
COMMAND="$COMMAND --title \"${{ inputs.pr_title }}\""
COMMAND+=(--title "${{ inputs.pr_title }}")
else
COMMAND="$COMMAND --fill"
COMMAND+=(--fill)
fi
if [[ ! -z "${{ inputs.pr_body }}" ]]; then
COMMAND="$COMMAND --body \"${{ inputs.pr_body }}\""
COMMAND+=(--body "${{ inputs.pr_body }}")
fi
if [[ ! -z "${{ inputs.pr_reviewer }}" ]]; then
COMMAND="$COMMAND --reviewer \"${{ inputs.pr_reviewer }}\""
COMMAND+=(--reviewer "${{ inputs.pr_reviewer }}")
fi
if [[ ! -z "${{ inputs.pr_assignee }}" ]]; then
COMMAND="$COMMAND --assignee \"${{ inputs.pr_assignee }}\""
COMMAND+=(--assignee "${{ inputs.pr_assignee }}")
fi
if [[ ! -z "${{ inputs.pr_label }}" ]]; then
COMMAND="$COMMAND --label \"${{ inputs.pr_label }}\""
COMMAND+=(--label "${{ inputs.pr_label }}")
fi
if [[ ! -z "${{ inputs.pr_milestone }}" ]]; then
COMMAND="$COMMAND --milestone \"${{ inputs.pr_milestone }}\""
COMMAND+=(--milestone "${{ inputs.pr_milestone }}")
fi
if [[ "${{ inputs.pr_draft }}" == "true" ]]; then
COMMAND="$COMMAND --draft"
COMMAND+=(--draft)
fi
COMMAND="$COMMAND || true"
echo "Command that will be executed:"
echo "$COMMAND"
PR_URL=$(sh -c "$COMMAND")
if [[ "$?" != "0" ]]; then
exit 1
fi
echo ${PR_URL}
echo "::set-output name=pr_url::${PR_URL}"
echo "::set-output name=pr_number::${PR_URL##*/}"
echo "Command that will be executed: ${COMMAND[@]}"
# SYNTAX:
# catch STDOUT_VARIABLE STDERR_VARIABLE COMMAND [ARG1[ ARG2[ ...[ ARGN]]]]
catch() {
{
IFS=$'\n' read -r -d '' "${1}";
IFS=$'\n' read -r -d '' "${2}";
(IFS=$'\n' read -r -d '' _ERRNO_; return ${_ERRNO_});
} < <((printf '\0%s\0%d\0' "$(((({ shift 2; "${@}"; echo "${?}" 1>&3-; } | tr -d '\0' 1>&4-) 4>&2- 2>&1- | tr -d '\0' 1>&4-) 3>&1- | exit "$(cat)") 4>&1-)" "${?}" 1>&2) 2>&1)
}
set +e
catch PR_URL pr_command_error "${COMMAND[@]}"
pr_command_exit_code=$?
set -e
echo "Output of github cli command: " ${PR_URL} ${pr_command_error}
echo "pr_url=${PR_URL}" >> "$GITHUB_OUTPUT"
echo "pr_number=${PR_URL##*/}" >> "$GITHUB_OUTPUT"
if [[ "$LINES_CHANGED" = "0" ]]; then
echo "::set-output name=has_changed_files::false"
echo "has_changed_files=false" >> "$GITHUB_OUTPUT"
else
echo "::set-output name=has_changed_files::true"
echo "has_changed_files=true" >> "$GITHUB_OUTPUT"
fi
if [[ "$pr_command_exit_code" != "0" ]]; then
exit 1
fi
echo "pr_created=true" >> "$GITHUB_OUTPUT"
shell: bash

branding:
icon: 'git-pull-request'
color: 'black'
color: 'blue'

0 comments on commit 16eed67

Please sign in to comment.