mirror of
https://github.com/tomasriveral/nixos.git
synced 2026-08-11 18:18:37 +02:00
106 lines
2.9 KiB
YAML
106 lines
2.9 KiB
YAML
name: Sync branches into main
|
|
|
|
on:
|
|
schedule:
|
|
- cron: "0 14 * * 1" # Monday
|
|
- cron: "0 14 * * 3" # Wednesday
|
|
|
|
workflow_dispatch:
|
|
inputs:
|
|
source:
|
|
description: Branch to sync into main
|
|
required: true
|
|
type: choice
|
|
options:
|
|
- laptop
|
|
- desktop
|
|
|
|
permissions:
|
|
contents: write
|
|
pull-requests: write
|
|
|
|
jobs:
|
|
sync:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Determine source branch
|
|
id: branch
|
|
run: |
|
|
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
|
echo "source=${{ inputs.source }}" >> "$GITHUB_OUTPUT"
|
|
exit 0
|
|
fi
|
|
|
|
DOW=$(date -u +%u)
|
|
|
|
if [ "$DOW" = "1" ]; then
|
|
echo "source=laptop" >> "$GITHUB_OUTPUT"
|
|
elif [ "$DOW" = "3" ]; then
|
|
echo "source=desktop" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "No sync scheduled today."
|
|
exit 1
|
|
fi
|
|
|
|
- name: Check for existing PR
|
|
id: existing
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
REPO: ${{ github.repository }}
|
|
run: |
|
|
PR_NUMBER=$(gh pr list \
|
|
--base main \
|
|
--repo "$REPO" \
|
|
--head "${{ steps.branch.outputs.source }}" \
|
|
--state open \
|
|
--json number \
|
|
--jq '.[0].number')
|
|
|
|
echo "number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Create PR if needed
|
|
id: pr
|
|
if: steps.existing.outputs.number == ''
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
PR_URL=$(gh pr create \
|
|
--base main \
|
|
--repo "$REPO" \
|
|
--head "${{ steps.branch.outputs.source }}" \
|
|
--title "Weekly sync: ${{ steps.branch.outputs.source }} → main" \
|
|
--body "$(cat <<EOF
|
|
This pull request was created automatically by GitHub Actions.
|
|
|
|
If the branch can be merged cleanly, auto-merge will merge it automatically.
|
|
|
|
If there are merge conflicts, this PR will remain open until they are resolved.
|
|
EOF
|
|
)")
|
|
|
|
PR_NUMBER=$(gh pr view "$PR_URL" --json number --jq '.number')
|
|
|
|
echo "url=$PR_URL" >> "$GITHUB_OUTPUT"
|
|
echo "number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Determine PR number
|
|
id: final
|
|
run: |
|
|
if [ -n "${{ steps.existing.outputs.number }}" ]; then
|
|
echo "number=${{ steps.existing.outputs.number }}" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "number=${{ steps.pr.outputs.number }}" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Enable auto-merge
|
|
if: steps.final.outputs.number != ''
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
gh pr merge \
|
|
"${{ steps.final.outputs.number }}" \
|
|
--repo "$REPO" \
|
|
--auto \
|
|
--merge
|