|
| 1 | +--- |
| 2 | +name: Apply labels for backporting |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_call: |
| 6 | + inputs: |
| 7 | + label_major_release: |
| 8 | + default: "do_not_backport" |
| 9 | + required: false |
| 10 | + type: string |
| 11 | + description: | |
| 12 | + The label to apply if the PR includes a change that would necessitate a major release. |
| 13 | + label_minor_release: |
| 14 | + required: true |
| 15 | + type: string |
| 16 | + description: | |
| 17 | + The label to apply if the PR only includes a change that would necessitate a minor |
| 18 | + release. This will also be applied by default if the PR doesn't necessitate a major |
| 19 | + release. |
| 20 | + label_bugfix_release: |
| 21 | + required: true |
| 22 | + type: string |
| 23 | + description: | |
| 24 | + The label to apply if the PR only includes a bugfix or security release. |
| 25 | + label_skip: |
| 26 | + default: "do_not_backport" |
| 27 | + required: false |
| 28 | + type: string |
| 29 | + description: | |
| 30 | + If this label has been applied, then the PR will not be re-assessed. |
| 31 | + label_mergeit: |
| 32 | + default: "mergeit" |
| 33 | + required: false |
| 34 | + type: string |
| 35 | + description: | |
| 36 | + Which label will be used to trigger labelling for minor/bugfix backporting. |
| 37 | + We look for major releases when a change is pushed, and minor/bugfixes when the PR |
| 38 | + has been approved for merging and the mergeit label has been applied to trigger |
| 39 | + the merge. |
| 40 | +
|
| 41 | +jobs: |
| 42 | + changelog-types: |
| 43 | + # We always skip if do_not_backport has previously been applied. |
| 44 | + # Otherwise, if someone applies 'mergeit', opens the PR, or pushes a new commit |
| 45 | + # we'll examine the contents of changelog fragments to try to guess the best backport strategy. |
| 46 | + if: ${{ |
| 47 | + ! contains(github.event.pull_request.labels.*.name, inputs.label_skip) |
| 48 | + && ( |
| 49 | + (github.event.action == 'labeled' && github.event.label.name == inputs.label_mergeit) |
| 50 | + || (github.event.action == 'synchronize') |
| 51 | + || (github.event.action == 'opened') |
| 52 | + ) |
| 53 | + }} |
| 54 | + permissions: |
| 55 | + pull-requests: read |
| 56 | + runs-on: ubuntu-latest |
| 57 | + outputs: |
| 58 | + no_backport: ${{ steps.evaluate.outputs.major_release }} |
| 59 | + bugfix: ${{ steps.evaluate.outputs.bugfix_release }} |
| 60 | + minor_only: ${{ steps.evaluate.outputs.minor_release }} |
| 61 | + steps: |
| 62 | + - name: Evaluate change types |
| 63 | + id: evaluate |
| 64 | + uses: ansible-network/github_actions/.github/actions/changelog_evaluator@main |
| 65 | + |
| 66 | + changelog-labeling: |
| 67 | + permissions: |
| 68 | + pull-requests: write |
| 69 | + runs-on: ubuntu-latest |
| 70 | + needs: |
| 71 | + - changelog-types |
| 72 | + steps: |
| 73 | + - name: Strip tags for backporting and apply do_not_backport |
| 74 | + id: no-backport |
| 75 | + # If breaking_changes or major_changes are pushed, then we always apply do_not_backport |
| 76 | + # and strip any existing backport-* labels |
| 77 | + if: ${{ needs.changelog-types.outputs.no_backport == '0' }} |
| 78 | + uses: ansible-network/github_actions/.github/actions/changelog_labeller@main |
| 79 | + with: |
| 80 | + purge_labels: true |
| 81 | + label_to_add: ${{ inputs.label_major_release }} |
| 82 | + |
| 83 | + - name: Apply tag for backporting to at least the most recent major release |
| 84 | + id: minor-only |
| 85 | + if: ${{ |
| 86 | + (github.event.action == 'labeled' && github.event.label.name == inputs.label_mergeit ) |
| 87 | + && ! ( needs.changelog-types.outputs.no_backport == '0' ) |
| 88 | + && ( |
| 89 | + ( needs.changelog-types.outputs.minor_only == '0' ) |
| 90 | + || ! (needs.changelog-types.outputs.bugfix == '0' ) |
| 91 | + ) |
| 92 | + }} |
| 93 | + uses: ansible-network/github_actions/.github/actions/changelog_labeller@main |
| 94 | + with: |
| 95 | + label_to_add: ${{ inputs.label_minor_release }} |
| 96 | + |
| 97 | + - name: Apply tag for backporting to at least the two most recent major releases |
| 98 | + id: security-or-bugfix |
| 99 | + if: ${{ |
| 100 | + (github.event.action == 'labeled' && github.event.label.name == inputs.label_mergeit ) |
| 101 | + && ! ( needs.changelog-types.outputs.no_backport == '0' ) |
| 102 | + && ! ( needs.changelog-types.outputs.minor_only == '0' ) |
| 103 | + && ( needs.changelog-types.outputs.bugfix == '0' ) |
| 104 | + }} |
| 105 | + uses: ansible-network/github_actions/.github/actions/changelog_labeller@main |
| 106 | + with: |
| 107 | + label_to_add: ${{ inputs.label_minor_release }},${{ inputs.label_bugfix_release }} |
0 commit comments