Skip to content

Instantly share code, notes, and snippets.

@tksst
Created November 20, 2022 08:48
Show Gist options
  • Save tksst/61e394f4b064cee3479bdc980b40b7eb to your computer and use it in GitHub Desktop.
Save tksst/61e394f4b064cee3479bdc980b40b7eb to your computer and use it in GitHub Desktop.
Check if the branch is tied to Pull Request
name: Check if the branch is tied to PR
on:
workflow_call:
outputs:
tied-to-pr:
description: Whether the branch is tied to PR or not
value: ${{ jobs.check-pr.outputs.tied-to-pr }}
jobs:
check-pr:
name: Check if the branch is tied to PR
runs-on: ubuntu-latest
outputs:
tied-to-pr: ${{ ( github.event_name != 'push' || github.event.created ) && 'false' || env.tied-to-pr }}
steps:
- name: Checkout the source
if: github.event_name == 'push' && !github.event.created
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # tag=v3.1.0
- name: Check if the branch is tied to PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: github.event_name == 'push' && !github.event.created
run: |
pr_state=$( gh pr view --json state -q .state || echo '')
echo "pr state: $pr_state"
{
echo -n "tied-to-pr="
if [[ $pr_state == "OPEN" ]]; then
echo "true"
else
echo "false"
fi
} | tee -a "$GITHUB_ENV"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment