mirror of
https://github.com/tomasriveral/nixos.git
synced 2026-08-11 18:18:37 +02:00
CI: rewrite with checkout
This commit is contained in:
@@ -24,6 +24,9 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Determine source branch
|
- name: Determine source branch
|
||||||
id: branch
|
id: branch
|
||||||
run: |
|
run: |
|
||||||
@@ -34,24 +37,47 @@ jobs:
|
|||||||
|
|
||||||
DOW=$(date -u +%u)
|
DOW=$(date -u +%u)
|
||||||
|
|
||||||
if [ "$DOW" = "1" ]; then
|
case "$DOW" in
|
||||||
echo "source=laptop" >> "$GITHUB_OUTPUT"
|
1)
|
||||||
elif [ "$DOW" = "3" ]; then
|
echo "source=laptop" >> "$GITHUB_OUTPUT"
|
||||||
echo "source=desktop" >> "$GITHUB_OUTPUT"
|
;;
|
||||||
else
|
3)
|
||||||
echo "No sync scheduled today."
|
echo "source=desktop" >> "$GITHUB_OUTPUT"
|
||||||
exit 1
|
;;
|
||||||
fi
|
*)
|
||||||
|
echo "No sync scheduled today."
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
- name: Check for existing PR
|
- name: Check for existing PR
|
||||||
id: existing
|
id: existing
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
REPO: ${{ github.repository }}
|
|
||||||
run: |
|
run: |
|
||||||
PR_NUMBER=$(gh pr list \
|
PR_NUMBER=$(gh pr list \
|
||||||
--base main \
|
--base main \
|
||||||
--repo "$REPO" \
|
--head "${{ steps.branch.outputs.source }}" \
|
||||||
|
--state open \
|
||||||
|
--json number \
|
||||||
|
--jq '.[0].number // empty')
|
||||||
|
|
||||||
|
echo "number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Create PR
|
||||||
|
id: create
|
||||||
|
if: steps.existing.outputs.number == ''
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
gh pr create \
|
||||||
|
--base main \
|
||||||
|
--head "${{ steps.branch.outputs.source }}" \
|
||||||
|
--title "Weekly sync: ${{ steps.branch.outputs.source }} → main" \
|
||||||
|
--body "This pull request was created automatically by GitHub Actions."
|
||||||
|
|
||||||
|
PR_NUMBER=$(gh pr list \
|
||||||
|
--base main \
|
||||||
--head "${{ steps.branch.outputs.source }}" \
|
--head "${{ steps.branch.outputs.source }}" \
|
||||||
--state open \
|
--state open \
|
||||||
--json number \
|
--json number \
|
||||||
@@ -59,47 +85,21 @@ jobs:
|
|||||||
|
|
||||||
echo "number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
|
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
|
- name: Determine PR number
|
||||||
id: final
|
id: pr
|
||||||
run: |
|
run: |
|
||||||
if [ -n "${{ steps.existing.outputs.number }}" ]; then
|
if [ -n "${{ steps.existing.outputs.number }}" ]; then
|
||||||
echo "number=${{ steps.existing.outputs.number }}" >> "$GITHUB_OUTPUT"
|
echo "number=${{ steps.existing.outputs.number }}" >> "$GITHUB_OUTPUT"
|
||||||
else
|
else
|
||||||
echo "number=${{ steps.pr.outputs.number }}" >> "$GITHUB_OUTPUT"
|
echo "number=${{ steps.create.outputs.number }}" >> "$GITHUB_OUTPUT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Enable auto-merge
|
- name: Enable auto-merge
|
||||||
if: steps.final.outputs.number != ''
|
if: steps.pr.outputs.number != ''
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
gh pr merge \
|
gh pr merge \
|
||||||
"${{ steps.final.outputs.number }}" \
|
"${{ steps.pr.outputs.number }}" \
|
||||||
--repo "$REPO" \
|
|
||||||
--auto \
|
--auto \
|
||||||
--merge
|
--merge
|
||||||
|
|||||||
Reference in New Issue
Block a user