Dismiss old FMA PRs after creating a new one (#27359)

We have a scheduled action to create an "Update Fleet-maintained apps"
PR with the latest updates for FMAs. The bot creates a new PR each time,
even if the previous PRs haven't been merged. Since the latest PR will
always have all the latest updates, it's unnecessary to keep the old
ones around. We should have the bot close the old PRs once the new one
is opened. Additionally it was recommended that assignees be added to
the PR.

This PR updates the action to:

1. Find existing "Update Fleet-maintained apps" PRs created by the bot
2. Get the list of Github IDs of the devs on the software product team
3. Creates a new PR as usual, adding the devs as assignees
4. If the new PR is created successfully, closes the old PRs with
comments linking to the new PR

See a successful run
[here](https://github.com/fleetdm/fleet/actions/runs/13977643317/job/39135240445),
+ the resulting PR [here](https://github.com/fleetdm/fleet/pull/27357)

---------

Co-authored-by: Tim Lee <timlee@fleetdm.com>
This commit is contained in:
Scott Gress 2025-03-21 09:32:02 -05:00 committed by GitHub
parent 735328c1e7
commit bbe3f18b88
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -53,7 +53,34 @@ jobs:
go mod download
go run cmd/maintained-apps/main.go
- name: Search for Existing PRs
id: search_pr
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:
script: |
const { data: pullRequests } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
per_page: 100
});
return pullRequests.filter(pr => pr.title.includes('Update Fleet-maintained apps') && pr.user.login === 'github-actions[bot]').map(pr => pr.number);
- name: Get Assignee IDs
id: get_assignee_ids
run: |
# DEVS=$(awk '/### Software group/{flag=1; next} /#/{flag=0} flag' ./fleet/handbook/company/product-groups.md | awk '/\| Developer[ ]*\|/ {sub(/\| Developer[ ]*\|/, ""); print}' | grep -o '@[^]]*' | tr -d '@' | tr '\n' ',' | sed 's/,$//')
# :-(
DEVS="iansltx,jahzielv,mostlikelee,ksykulev"
echo "github_ids=$DEVS" >> ${GITHUB_OUTPUT}
- name: Log Info
run: |
echo "Will close existing PRs: ${{ steps.search_pr.outputs.result }}"
echo "Will assign new PR to: ${{ steps.get_assignee_ids.outputs.github_ids }}"
- name: Create Pull Request
id: create-pr
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e #v7.0.8
with:
base: main
@ -66,5 +93,26 @@ jobs:
Generated automatically with cmd/maintained-apps.
body: Automated ingestion of latest Fleet-maintained app data.
assignees: ${{ steps.get_assignee_ids.outputs.github_ids }}
- name: Close Existing PRs
if: steps.search_pr.outputs.result != '[]'
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:
script: |
const prNumbers = JSON.parse('${{ steps.search_pr.outputs.result }}');
const newPrNumber = '${{ steps.create-pr.outputs.pull-request-number }}';
for (const prNumber of prNumbers) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `Closing in favor of #${newPrNumber}.`,
});
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
state: 'closed',
});
}