Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add breaking/dangerous/safe messages to action output #2690

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arxeiss
Copy link

@arxeiss arxeiss commented Jan 29, 2024

Description

After the Github Application deprecation (#2648 ) I need to write custom Github workflow to send result to Slack. However, current Github Action does not allow that, because is not exposing the result - only total amount of changes.

Fixes #2689

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

Created Github workflow with custom scripts

Custom Github Workflow
---
name: GraphQL Inspector Slack notification
on:
    push:
        branches:
            - master
        paths:
            - services/console/schema.graphql

jobs:
    inspector:
        name: GraphQL Inspector
        runs-on: ubuntu-latest
        steps:
            - name: Checkout codebase
              uses: actions/checkout@v4
              with:
                  fetch-depth: 20   # In last 20 commits must be some tag
                  fetch-tags: true

            - name: Get last published tag
              id: last-tag
              run: |
                  last_tag=$(git for-each-ref --count=1 --sort=-v:refname --format '%(refname:short)' 'refs/tags/v*')
                  echo "Last released tag: $last_tag"
                  echo "last-tag=$last_tag" >> $GITHUB_OUTPUT

            - name: Run inspector
              id: inspector
              uses: indykite/graphql-inspector@add-output-options
              with:
                  name: Console GraphQL Inspector
                  schema: ${{ steps.last-tag.outputs.last-tag }}:services/console/schema.graphql
                  experimental_merge: false
                  fail-on-breaking: false     # Never fail, it is here just to send notifications
                  create-action-check: false     # No need check
                  annotations: false     # It would set annotations on auto-generated schema anyway. Just disable it.

            - name: Format Slack attachments
              id: formatting
              if: ${{ steps.inspector.outputs.changes > 0 }}
              uses: actions/github-script@v7
              with:
                  script: |
                      let breaking = ${{ steps.inspector.outputs.breaking-changes }} || [];
                      let dangerous = ${{ steps.inspector.outputs.dangerous-changes }} || [];
                      let safe = ${{ steps.inspector.outputs.safe-changes }} || [];

                      breaking = breaking.map((e) => e.replace(/'/g, "`")).join("\n- ");
                      dangerous = dangerous.map((e) => e.replace(/'/g, "`")).join("\n- ");
                      safe = safe.map((e) => e.replace(/'/g, "`")).join("\n- ");

                      const attachments = [];
                      if (breaking.length > 0) {
                          attachments.push({
                              mrkdwn_in: ["text"],
                              color: "#bb0c0c",
                              title: "Breaking changes",
                              text: "- " + breaking,
                          });
                      }
                      if (dangerous.length > 0) {
                          attachments.push({
                              mrkdwn_in: ["text"],
                              color: "#bb6b0c",
                              title: "Dangerous changes",
                              text: "- " + dangerous,
                          });
                      }
                      if (safe.length > 0) {
                          attachments.push({
                              mrkdwn_in: ["text"],
                              color: "#319a0c",
                              title: "Safe changes",
                              text: "- " + safe,
                          });
                      }

                      core.setOutput("attachments", attachments);

            - name: Send Slack notification
              if: ${{ steps.inspector.outputs.changes > 0 }}
              uses: slackapi/[email protected]
              with:
                      # For posting a rich message using Block Kit
                  payload: |
                      {
                          "blocks": [
                              {
                                  "type": "header",
                                  "text": {
                                      "type": "plain_text",
                                      "text": "Changes in GraphQL schema released :rocket:"
                                  }
                              },
                              {
                                  "type": "section",
                                  "text": {
                                      "type": "mrkdwn",
                                      "text": ":sleuth_or_spy: I have found *${{ steps.inspector.outputs.changes }}* changes in GraphQL schema."
                                  }
                              }
                          ],
                          "attachments": ${{ steps.formatting.outputs.attachments }}
                      }
              env:
                  SLACK_WEBHOOK_URL: ${{ secrets.GQL_INSPECTOR_ACTION_WEBHOOK }}
                  SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK

Test Environment:

  • Github Aciton

Checklist:

  • I have followed the
    CONTRIBUTING doc and the
    style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose
the solution you did and what alternatives you considered, etc...

Copy link

changeset-bot bot commented Jan 29, 2024

⚠️ No Changeset found

Latest commit: 5123440

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@arxeiss arxeiss force-pushed the add-output-options branch 2 times, most recently from 7411b7c to f8c6ab3 Compare March 21, 2024 13:15
@arxeiss
Copy link
Author

arxeiss commented May 24, 2024

I see you are preparing v5.0.0. Would it be possible to include there this feature please?

@nembence
Copy link

@TuvalSimha this is a really needed feature please include this PR in the next version to being able to send Slack notifications. @arxeiss thanks for taking the initiative 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add changes result to Github Action output
2 participants