Update Graphql API #311
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: "Update Graphql API" | |
| on: | |
| schedule: | |
| - cron: "0 */12 * * *" | |
| workflow_call: | |
| workflow_dispatch: | |
| jobs: | |
| update-graphql-api: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Code Checkout | |
| uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | |
| - name: Import environment variables from file | |
| run: cat ".github/env" >> $GITHUB_ENV | |
| - name: Set up Go | |
| uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0 | |
| with: | |
| go-version: ">=${{ env.golang-version }}" | |
| cache: false | |
| - name: Generate Graphql Schema | |
| run: | | |
| MONDOO_API_TOKEN=${{ secrets.MONDOO_API_TOKEN }} make generate | |
| - name: Prepare title and branch name | |
| id: branch | |
| run: | | |
| BRANCH_NAME="schema/update_$(date +'%Y%m%d%H%M%S')" | |
| COMMIT_MSG="🧹 Bump GraphQL Schema - $(date +'%Y%m%d%H%M%S')" | |
| echo "COMMIT_TITLE=${COMMIT_MSG}" >> $GITHUB_OUTPUT | |
| echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_OUTPUT | |
| - name: Check git diff | |
| id: git-diff | |
| run: | | |
| DIFF=$(git status --porcelain | wc -l) | |
| echo "GIT_DIFF=${DIFF}" >> $GITHUB_OUTPUT | |
| - name: Create PR | |
| if: steps.git-diff.outputs.GIT_DIFF != '0' | |
| id: cpr | |
| uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1 | |
| with: | |
| base: main | |
| labels: dependencies,go | |
| committer: "Mondoo Tools <tools@mondoo.com>" | |
| commit-message: ${{ steps.branch.outputs.COMMIT_TITLE }} | |
| author: "Mondoo Tools <tools@mondoo.com>" | |
| title: ${{ steps.branch.outputs.COMMIT_TITLE }} | |
| branch: ${{ steps.branch.outputs.BRANCH_NAME }} | |
| body-path: .github/pr-body.md | |
| - name: PR infos | |
| if: ${{ steps.cpr.outputs.pull-request-number }} | |
| run: | | |
| echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" | |
| echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" | |
| # fetch a token for the mondoo-mergebot app | |
| - name: Generate token | |
| if: ${{ steps.cpr.outputs.pull-request-number }} | |
| id: generate-token | |
| uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0 | |
| with: | |
| # client-id accepts the same value as the old app-id input, see | |
| # https://github.com/actions/create-github-app-token/blob/v3.1.1/main.js#L21 | |
| client-id: ${{ secrets.MONDOO_MERGEBOT_APP_ID }} | |
| private-key: ${{ secrets.MONDOO_MERGEBOT_APP_PRIVATE_KEY }} | |
| # automerge using bot token | |
| - name: Approve and merge a PR | |
| if: ${{ steps.cpr.outputs.pull-request-number }} | |
| run: | | |
| gh pr review ${{ steps.cpr.outputs.pull-request-number }} --approve | |
| gh pr merge ${{ steps.cpr.outputs.pull-request-number }} --squash | |
| env: | |
| GH_TOKEN: ${{ steps.generate-token.outputs.token }} |