mirror of
https://github.com/nix-community/nixvim.git
synced 2025-07-13 10:44:34 +02:00
ci/update: backport changes from main
This commit is contained in:
parent
3eafee65e0
commit
82440e1d4e
1 changed files with 180 additions and 38 deletions
218
.github/workflows/update.yml
vendored
218
.github/workflows/update.yml
vendored
|
@ -1,8 +1,8 @@
|
||||||
name: update
|
name: Update
|
||||||
on:
|
on:
|
||||||
# Runs every Saturday at noon
|
# Runs everyday at noon
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "0 12 * * SAT"
|
- cron: "0 12 * * *"
|
||||||
# Allow manual triggering
|
# Allow manual triggering
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
|
@ -14,18 +14,18 @@ on:
|
||||||
type: boolean
|
type: boolean
|
||||||
default: true
|
default: true
|
||||||
description: Update generated files
|
description: Update generated files
|
||||||
nixos-24.05:
|
re_apply:
|
||||||
type: boolean
|
type: boolean
|
||||||
description: Also update nixos-24.05
|
default: true
|
||||||
|
description: Re-apply additional commits from the PR
|
||||||
|
|
||||||
# Allow one concurrent update per branch
|
# Allow one concurrent update per branch
|
||||||
concurrency:
|
concurrency:
|
||||||
group: "update-${{ github.ref_name }}"
|
group: "update-${{ github.ref_name }}"
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
# Allow running workflows, pushing and creating PRs
|
# Allow pushing and creating PRs
|
||||||
permissions:
|
permissions:
|
||||||
actions: write
|
|
||||||
contents: write
|
contents: write
|
||||||
pull-requests: write
|
pull-requests: write
|
||||||
|
|
||||||
|
@ -35,6 +35,10 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 40
|
timeout-minutes: 40
|
||||||
if: github.event_name != 'schedule' || github.repository == 'nix-community/nixvim'
|
if: github.event_name != 'schedule' || github.repository == 'nix-community/nixvim'
|
||||||
|
env:
|
||||||
|
repo: ${{ github.repository }}
|
||||||
|
base_branch: ${{ github.ref_name }}
|
||||||
|
pr_branch: update/${{ github.ref_name }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
|
@ -42,14 +46,6 @@ jobs:
|
||||||
with:
|
with:
|
||||||
ssh-key: ${{ secrets.CI_UPDATE_SSH_KEY }}
|
ssh-key: ${{ secrets.CI_UPDATE_SSH_KEY }}
|
||||||
|
|
||||||
# NOTE: If additional "inputs" are added, copy this step
|
|
||||||
- name: Update nixos-24.05
|
|
||||||
if: inputs['nixos-24.05'] || github.event_name == 'schedule'
|
|
||||||
env:
|
|
||||||
GH_TOKEN: ${{ github.token }}
|
|
||||||
run: |
|
|
||||||
gh workflow run update.yml --ref nixos-24.05
|
|
||||||
|
|
||||||
- name: Install Nix
|
- name: Install Nix
|
||||||
uses: cachix/install-nix-action@v30
|
uses: cachix/install-nix-action@v30
|
||||||
with:
|
with:
|
||||||
|
@ -61,6 +57,49 @@ jobs:
|
||||||
git config user.name 'github-actions[bot]'
|
git config user.name 'github-actions[bot]'
|
||||||
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
|
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
|
||||||
|
|
||||||
|
- name: Create update branch
|
||||||
|
run: |
|
||||||
|
git branch -D "$pr_branch" || echo "Nothing to delete"
|
||||||
|
git switch -c "$pr_branch"
|
||||||
|
|
||||||
|
- name: Get info on the current PR
|
||||||
|
id: open_pr_info
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
# Query for info about the already open update PR
|
||||||
|
info=$(
|
||||||
|
gh api graphql -F owner='{owner}' -F repo='{repo}' -F branch="$pr_branch" -f query='
|
||||||
|
query($owner:String!, $repo:String!, $branch:String!) {
|
||||||
|
repository(owner: $owner, name: $repo) {
|
||||||
|
pullRequests(first: 1, states: OPEN, headRefName: $branch) {
|
||||||
|
nodes {
|
||||||
|
number
|
||||||
|
url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
' | jq --raw-output '
|
||||||
|
.data.repository.pullRequests.nodes[]
|
||||||
|
| to_entries[]
|
||||||
|
| "\(.key)=\(.value)"
|
||||||
|
'
|
||||||
|
)
|
||||||
|
if [[ -n "$info" ]]; then
|
||||||
|
echo "PR info:"
|
||||||
|
echo "$info"
|
||||||
|
echo "$info" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "No PR is currently open"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Fetch current PR's branch
|
||||||
|
if: steps.open_pr_info.outputs.number
|
||||||
|
run: |
|
||||||
|
git fetch origin "$pr_branch"
|
||||||
|
git branch --set-upstream-to "origin/$pr_branch"
|
||||||
|
|
||||||
- name: Update flake.lock
|
- name: Update flake.lock
|
||||||
id: flake_lock
|
id: flake_lock
|
||||||
if: inputs.lock || github.event_name == 'schedule'
|
if: inputs.lock || github.event_name == 'schedule'
|
||||||
|
@ -97,13 +136,52 @@ jobs:
|
||||||
echo "EOF" >> "$GITHUB_OUTPUT"
|
echo "EOF" >> "$GITHUB_OUTPUT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Create Pull Request
|
- name: Apply commits from the open PR
|
||||||
id: pr
|
id: re_apply
|
||||||
uses: peter-evans/create-pull-request@v6
|
if: (inputs.re_apply || github.event_name == 'schedule') && steps.open_pr_info.outputs.number
|
||||||
with:
|
run: |
|
||||||
add-paths: "!**"
|
# The base is the most recent commit on the remote branch by github-actions[bot]
|
||||||
branch: update/${{ github.ref_name }}
|
# This should be a flake.lock bump or a generated-files update
|
||||||
delete-branch: true
|
# We will cherry-pick all commits on the remote _after_ the $base commit
|
||||||
|
remote="origin/$pr_branch"
|
||||||
|
author_rxp='^github-actions\[bot\] <41898282+github-actions\[bot\]@users\.noreply\.github\.com>$'
|
||||||
|
base=$(git rev-list --author="$author_rxp" --max-count=1 "$remote")
|
||||||
|
commits=( $(git rev-list --reverse "$base..$remote") )
|
||||||
|
if [[ -n "$commits" ]]; then
|
||||||
|
echo "Applying ${#commits[@]} commits..."
|
||||||
|
echo "count=${#commits[@]}" >> $GITHUB_OUTPUT
|
||||||
|
git cherry-pick --strategy-option=theirs "${commits[@]}"
|
||||||
|
else
|
||||||
|
echo "Nothing to re-apply"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Check if there are differences to push
|
||||||
|
id: diff
|
||||||
|
env:
|
||||||
|
pr_num: ${{ steps.open_pr_info.outputs.number }}
|
||||||
|
run: |
|
||||||
|
if [[ -n "$pr_num" ]]; then
|
||||||
|
remote="origin/$pr_branch"
|
||||||
|
else
|
||||||
|
remote="origin/$base_branch"
|
||||||
|
fi
|
||||||
|
diff=( $(git diff --cached --name-only "$remote") )
|
||||||
|
if [[ -n "$diff" ]]; then
|
||||||
|
echo "${#diff[@]} files different to $remote"
|
||||||
|
for file in "${diff[@]}"; do
|
||||||
|
echo "- $file"
|
||||||
|
done
|
||||||
|
echo "count=${#diff[@]}" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "No files are different to $remote"
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Create or Update Pull Request
|
||||||
|
id: updated_pr
|
||||||
|
if: steps.diff.outputs.count
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
pr_num: ${{ steps.open_pr_info.outputs.number }}
|
||||||
title: |
|
title: |
|
||||||
[${{ github.ref_name }}] Update flake.lock & generated files
|
[${{ github.ref_name }}] Update flake.lock & generated files
|
||||||
body: |
|
body: |
|
||||||
|
@ -114,24 +192,88 @@ jobs:
|
||||||
|
|
||||||
## Generate
|
## Generate
|
||||||
${{ steps.generate.outputs.body || 'No changes' }}
|
${{ steps.generate.outputs.body || 'No changes' }}
|
||||||
|
run: |
|
||||||
|
echo "Pushing to remote branch $pr_branch"
|
||||||
|
git push --force --set-upstream origin "$pr_branch"
|
||||||
|
|
||||||
|
if [[ -n "$pr_num" ]]; then
|
||||||
|
echo "Editing existing PR #$pr_num"
|
||||||
|
operation=updated
|
||||||
|
gh pr edit "$pr_num" --body "$body"
|
||||||
|
else
|
||||||
|
echo "Creating new PR"
|
||||||
|
operation=created
|
||||||
|
gh pr create \
|
||||||
|
--base "$base_branch" \
|
||||||
|
--title "$title" \
|
||||||
|
--body "$body"
|
||||||
|
fi
|
||||||
|
|
||||||
|
pr_info=$(
|
||||||
|
# Get info from `gh pr view`
|
||||||
|
gh pr view --json 'headRefName,number,url' --jq '
|
||||||
|
to_entries[]
|
||||||
|
| .key |=
|
||||||
|
# Rename headRefName -> branch
|
||||||
|
if . == "headRefName" then "branch"
|
||||||
|
else . end
|
||||||
|
| "\(.key)=\(.value)"
|
||||||
|
'
|
||||||
|
# Get additional info locally
|
||||||
|
echo "head=$(git rev-parse HEAD)"
|
||||||
|
echo "operation=$operation"
|
||||||
|
)
|
||||||
|
echo "PR Info:"
|
||||||
|
echo "$pr_info"
|
||||||
|
echo "$pr_info" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Print summary
|
- name: Print summary
|
||||||
if: ${{ steps.pr.outputs.pull-request-number }}
|
if: steps.updated_pr.outputs.number
|
||||||
|
env:
|
||||||
|
pr_num: ${{ steps.updated_pr.outputs.number }}
|
||||||
|
pr_url: ${{ steps.updated_pr.outputs.url }}
|
||||||
|
pr_branch: ${{ steps.updated_pr.outputs.branch }}
|
||||||
|
head: ${{ steps.updated_pr.outputs.head }}
|
||||||
|
operation: ${{ steps.updated_pr.outputs.operation }}
|
||||||
|
re_apply_count: ${{ steps.re_apply.outputs.count }}
|
||||||
run: |
|
run: |
|
||||||
num="${{ steps.pr.outputs.pull-request-number }}"
|
short=${head:0:6}
|
||||||
pr_url="${{ steps.pr.outputs.pull-request-url }}"
|
|
||||||
pr_branch="${{ steps.pr.outputs.pull-request-branch }}"
|
|
||||||
head="${{ steps.pr.outputs.pull-request-head-sha }}"
|
|
||||||
operation="${{ steps.pr.outputs.pull-request-operation }}"
|
|
||||||
|
|
||||||
# stdout
|
# stdout
|
||||||
echo "${head:0:6} pushed to ${pr_branch}"
|
echo "${short} pushed to ${pr_branch}"
|
||||||
echo "${pr} was ${operation}."
|
echo "#${pr_num} was ${operation}: ${pr_url}"
|
||||||
|
( # markdown summary
|
||||||
|
echo "## ${{ github.ref_name }}"
|
||||||
|
echo
|
||||||
|
echo "\`${short}\` pushed to \`${pr_branch}\`"
|
||||||
|
echo
|
||||||
|
echo "[#${pr_num}](${pr_url}) was ${operation}."
|
||||||
|
echo
|
||||||
|
if [[ -n "$re_apply_count" ]]; then
|
||||||
|
echo "Re-applied $re_apply_count commits from the existing PR."
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
) >> $GITHUB_STEP_SUMMARY
|
||||||
|
|
||||||
# markdown summary
|
- name: Print cancellation summary
|
||||||
echo "## ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
|
if: (!steps.updated_pr.outputs.number)
|
||||||
echo >> $GITHUB_STEP_SUMMARY
|
env:
|
||||||
echo "\`${head:0:6}\` pushed to \`${pr_branch}\`" >> $GITHUB_STEP_SUMMARY
|
pr_num: ${{ steps.open_pr_info.outputs.number }}
|
||||||
echo >> $GITHUB_STEP_SUMMARY
|
pr_url: ${{ steps.open_pr_info.outputs.url }}
|
||||||
echo "[#${num}](${pr_url}) was ${operation}." >> $GITHUB_STEP_SUMMARY
|
changes: ${{ steps.diff.outputs.count || '0' }}
|
||||||
echo >> $GITHUB_STEP_SUMMARY
|
re_apply_count: ${{ steps.re_apply.outputs.count }}
|
||||||
|
run: |
|
||||||
|
(
|
||||||
|
echo "## Not updated"
|
||||||
|
echo
|
||||||
|
echo -n "$changes files with differences compared to "
|
||||||
|
if [[ -n "$pr_num" ]]; then
|
||||||
|
echo "[#$pr_num]($pr_url)."
|
||||||
|
else
|
||||||
|
echo "\`$base_branch\`"
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
if [[ -n "$re_apply_count" ]]; then
|
||||||
|
echo "Re-applied $re_apply_count commits from the existing PR."
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
) >> $GITHUB_STEP_SUMMARY
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue