Update Fleet-maintained apps (#43743) #1326
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Ingest maintained apps | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'ee/maintained-apps/**' | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 14 * * *' | |
| - cron: '0 21 * * *' | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| jobs: | |
| build: | |
| permissions: | |
| contents: write # Required to push new branch | |
| pull-requests: write # Required to open PRs | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 180 | |
| steps: | |
| - name: Harden Runner | |
| uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0 | |
| with: | |
| egress-policy: audit | |
| - name: Get current date and time | |
| id: date | |
| run: echo "::set-output name=date::$(date +'%y%m%d%H%M')" | |
| - name: Checkout Fleet | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| with: | |
| repository: fleetdm/fleet | |
| fetch-depth: 1 | |
| ref: ${{ github.head_ref }} | |
| path: fleet | |
| - name: Setup Go | |
| uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0 | |
| with: | |
| cache: false | |
| go-version-file: 'fleet/go.mod' | |
| - name: Ingest maintained apps | |
| env: | |
| NETWORK_TEST_GITHUB_TOKEN: ${{ secrets.FLEET_RELEASE_GITHUB_PAT }} | |
| run: | | |
| cd fleet | |
| 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 === 'fleet-release').map(pr => pr.number); | |
| - name: Log Info | |
| run: | | |
| echo "Will close existing PRs: ${{ steps.search_pr.outputs.result }}" | |
| - name: Create Pull Request | |
| id: create-pr | |
| uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e #v7.0.8 | |
| with: | |
| token: ${{ secrets.FLEET_RELEASE_GITHUB_PAT }} | |
| base: main | |
| path: fleet | |
| branch: fma-${{ steps.date.outputs.date }} | |
| delete-branch: true | |
| title: "Update Fleet-maintained apps" | |
| commit-message: | | |
| Update Fleet-maintained apps. | |
| Generated automatically with cmd/maintained-apps. | |
| body: Automated ingestion of latest Fleet-maintained app data. | |
| reviewers: allenhouchins | |
| - 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', | |
| }); | |
| } |