Skip to content

Sync PocketMine-MP primary branches #25

Sync PocketMine-MP primary branches

Sync PocketMine-MP primary branches #25

name: Sync PocketMine-MP primary branches
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch to update'
required: true
type: choice
options:
- "*"
- minor-next
- major-next
schedule:
- cron: "0 0 * * *"
jobs:
merge:
name: Sync branches
runs-on: ubuntu-latest
steps:
- name: Get sync option
id: choice
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "branch=${{ github.event.inputs.branch }}" >> $GITHUB_OUTPUT
elif [[ "${{ github.event_name }}" == "schedule" ]]; then
echo "branch=*" >> $GITHUB_OUTPUT
else
echo "::error Unexpected event type ${{ github.event_name }}"
exit 1
fi
- name: Generate access token
id: token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.RESTRICTED_ACTIONS_APP_ID }}
private-key: ${{ secrets.RESTRICTED_ACTIONS_APP_KEY }}
owner: ${{ github.repository_owner }}
repositories: PocketMine-MP
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/PocketMine-MP # to allow testing on forks without editing the workflow
fetch-depth: 0
token: ${{ steps.token.outputs.token }}
- name: Get GitHub App User ID
id: get-user-id
run: echo "user-id=$(gh api "/users/${{ steps.token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.token.outputs.token }}
- name: Set Git config
run: |
git config user.name '${{ steps.token.outputs.app-slug }}[bot]'
git config user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.token.outputs.app-slug }}[bot]@users.noreply.github.com'
- name: Merge "stable" into "minor-next" and push changes
if: contains(fromJSON('["minor-next", "*"]'), steps.choice.outputs.branch)
run: |
LOWER_BRANCH="stable"
TARGET_BRANCH="minor-next"
git checkout -f "$TARGET_BRANCH"
git pull --no-commit --ff origin "$LOWER_BRANCH"
git commit \
-m "Merge '$LOWER_BRANCH' into '$TARGET_BRANCH'" \
-m "Automatic merge performed by: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
|| true # suppress error in case of fast-forward merge
git push
- name: Merge "minor-next" into "major-next" and push changes
if: contains(fromJSON('["major-next", "*"]'), steps.choice.outputs.branch)
run: |
LOWER_BRANCH="minor-next"
TARGET_BRANCH="major-next"
git checkout -f "$TARGET_BRANCH"
git pull --no-commit --ff origin "$LOWER_BRANCH"
git commit \
-m "Merge '$LOWER_BRANCH' into '$TARGET_BRANCH'" \
-m "Automatic merge performed by: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
|| true # suppress error in case of fast-forward merge
git push