summaryrefslogtreecommitdiff
path: root/.github/workflows/periodic-merge.yml
blob: 6fa5e699fc5d81bd5642c763226a66f4359445be (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
name: "Merge"

on:
  workflow_call:
    inputs:
      from:
        description: Branch to merge into target branch. Can also be two branches separated by space to find the merge base between them.
        required: true
        type: string
      into:
        description: Target branch to merge into.
        required: true
        type: string

defaults:
  run:
    shell: bash

jobs:
  merge:
    runs-on: ubuntu-24.04-arm
    timeout-minutes: 5
    steps:
      # Use a GitHub App to create the PR so that CI gets triggered
      # The App is scoped to Repository > Contents and Pull Requests: write for Nixpkgs
      - uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6
        id: app-token
        with:
          app-id: ${{ vars.NIXPKGS_CI_APP_ID }}
          private-key: ${{ secrets.NIXPKGS_CI_APP_PRIVATE_KEY }}
          permission-contents: write
          permission-pull-requests: write

      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

      - name: Find merge base between two branches
        if: contains(inputs.from, ' ')
        id: merge_base
        env:
          branches: ${{ inputs.from }}
        run: |
          # turn into bash array, split on space
          read -ra branches <<< "$branches"
          git fetch --shallow-since="1 month ago" origin "${branches[@]}"
          merge_base="$(git merge-base "refs/remotes/origin/${branches[0]}" "refs/remotes/origin/${branches[1]}")"
          echo "Found merge base: $merge_base" >&2
          echo "merge_base=$merge_base" >> "$GITHUB_OUTPUT"

      - name: ${{ inputs.from }} → ${{ inputs.into }}
        uses: devmasx/merge-branch@854d3ac71ed1e9deb668e0074781b81fdd6e771f # 1.4.0
        with:
          type: now
          from_branch: ${{ steps.merge_base.outputs.merge_base || inputs.from }}
          target_branch: ${{ inputs.into }}
          github_token: ${{ steps.app-token.outputs.token }}

      - name: Comment on failure
        uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
        if: ${{ failure() }}
        with:
          issue-number: 105153
          body: |
            Periodic merge from `${{ inputs.from }}` into `${{ inputs.into }}` has [failed](https://github.com/NixOS/nixpkgs/actions/runs/${{ github.run_id }}).
          token: ${{ steps.app-token.outputs.token }}