Skip to content
Draft
Changes from all 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
55 changes: 31 additions & 24 deletions .github/workflows/pr-open.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: PR Opened

on:
pull_request:
pull_request_target:
types: [opened, reopened]

jobs:
open-data-pr:
name: Open deadlock-data PR
Expand All @@ -15,62 +13,71 @@ jobs:
uses: actions/checkout@v4
with:
path: deadbot
# For forks, check out the base repo code, not the fork's code
ref: ${{ github.event.pull_request.base.ref }}

- name: Checkout deadlock-data repo
uses: actions/checkout@v4
with:
repository: deadlock-wiki/deadlock-data
path: deadlock-data
token: ${{ secrets.GH_TOKEN }}
token: ${{ secrets.GH_TOKEN }}

- name: Configure Git
working-directory: deadlock-data
working-directory: deadlock-data
run: |
git config --global user.email "deadbot1101@gmail.com"
git config --global user.name "Deadbot0"
git config pull.rebase true

- name: Set branch name
id: branch
run: |
IS_FORK=${{ github.event.pull_request.head.repo.full_name != github.repository }}
if [ "$IS_FORK" = "true" ]; then
# Prefix with actor to avoid collisions across forks
echo "name=fork-${{ github.actor }}-${{ github.head_ref }}" >> $GITHUB_OUTPUT
else
echo "name=${{ github.head_ref }}" >> $GITHUB_OUTPUT
fi

- name: Create working branch on deadlock-data repo
working-directory: deadlock-data
working-directory: deadlock-data
run: |
git fetch origin

if git ls-remote --exit-code --heads origin ${{ github.head_ref }}; then
BRANCH="${{ steps.branch.outputs.name }}"

if git ls-remote --exit-code --heads origin "$BRANCH"; then
# branch exists, update local branch
git switch ${{ github.head_ref }}
git pull origin ${{ github.head_ref }} -X ours
git switch "$BRANCH"
git pull origin "$BRANCH" -X ours
else
# create new local branch
git checkout -b ${{ github.head_ref }} origin/${{ github.event.pull_request.base.ref }}
git checkout -b "$BRANCH" origin/${{ github.event.pull_request.base.ref }}
fi

git commit --allow-empty -m "chore: empty commit to enable PR creation"
git push --force-with-lease --set-upstream origin ${{ github.head_ref }}

# Creates a PR to enable viewing the outcome of the deadbot changes
git push --force-with-lease --set-upstream origin "$BRANCH"

- name: Create PR on deadlock-data repo
id: create_data_pr
working-directory: deadlock-data
working-directory: deadlock-data
run: |
gh auth login --with-token <<< ${{ secrets.GH_TOKEN }}
BRANCH="${{ steps.branch.outputs.name }}"
pr_url=$(
gh pr create \
--head ${{ github.head_ref }} \
--head "$BRANCH" \
--base ${{ github.base_ref }} \
--title ${{ github.head_ref }} \
--title "$BRANCH" \
--body "_PR Auto-generated by [deadbot PR](https://github.com/deadlock-wiki/deadbot/pull/${{ github.event.number }})_"
)
echo "pr_url=$pr_url" >> $GITHUB_OUTPUT

# for a newly made PR, add the reference into the PR body
- name: Reference deadlock-data PR in deadbot PR body
if: steps.create_data_pr.outputs.pr_url != ''
working-directory: deadbot
working-directory: deadbot
run: |
current_body=$(gh pr view ${{ github.event.number }} --json body -q ".body")

new_body="$current_body

_Parsed data in [deadlock-data PR](${{ steps.create_data_pr.outputs.pr_url }}) - Reopen deadbot PR or run deploy workflow for this branch [here](https://github.com/deadlock-wiki/deadbot/actions/workflows/deploy.yaml) to reparse the data_"

gh pr edit ${{ github.event.number }} --body "$new_body"
gh pr edit ${{ github.event.number }} --body "$new_body"
Loading