Slack reminders for scorecards
This guide takes 7 minutes to complete, and aims to demonstrate:
- How to initiate changes in the organization using scorecards
- How to automate Slack reminders using Port's self service actions
- This guide assumes you have a Port account and that you have finished the onboarding process. We will use the
Service
blueprint that was created during the onboarding process. - You will need a Git repository in which you can place a workflow/pipeline that we will use in this guide. If you don't have one, we recommend creating a new repository named
Port-actions
.
The goal of this guideโ
In this guide we will create a self-service action that sends a Slack reminder for uncompleted scorecard rules. In reality, such an action can be used by R&D managers / Platform engineers to remind developers of unmet standards.
After completing it, you will get a sense of how it can benefit different personas in your organization:
- Developers will be notified about policies set by the platform engineer that need to be fixed.
- R&D managers & Platform engineers will be able to remind developers about unmet requirements in the services.
Setup the action's frontendโ
- Head to the Self-service page of your portal.
- Click on the
+ Action
button on the top left conner :
- Fill in the action's details as shown below:
- Title and Description
- Operation:
Create
- Blueprint:
Service
- icon:
Slack
This Self-service has no user inputs, click on the Next
button twice to proceed to the Backend
tab.
Define backend typeโ
Now we'll define the backend of the action. Port supports multiple invocation types, depending on the Git provider you are using.
- Github
- GitLab
Fill out the form with your values:
-
Replace the
Organization
andRepository
values with your values (this is where the workflow will reside and run). -
Name the workflow
port-slack-reminder.yml
. -
Fill out your workflow details:
-
Scroll down to the
Configure the invocation payload
section.
This is where you can define which data will be sent to your backend each time the action is executed.For this action, our backend only needs to know the id of the action run, so let's send it.
Copy the following JSON snippet and paste it in the payload code box:{
"runId": "{{ .run.id }}"
}
The last step is customizing the action's permissions. For simplicity's sake, we will use the default settings. For more information, see the permissions page. Click Save
.
Fill out the form:
- Choose
Trigger Webhook URL
as theInvocation type
. - Leave
Endpoint URL
blank for now, we will create it in the next section and come back to update it. - Fill the rest of the form out like this, then click
Next
:
-
Scroll down to the
Configure the invocation payload
section.
This is where you can define which data will be sent to your backend each time the action is executed.For this action, our backend only needs to know the id of the action run, so let's send it.
Copy the following JSON snippet and paste it in the payload code box:{
"runId": "{{ .run.id }}"
}
The last step is customizing the action's permissions. For simplicity's sake, we will use the default settings. For more information, see the permissions page. Click Save
.
The action's frontend is now ready ๐ฅณ
Setup the action's backendโ
Now we want to write the logic that our action will trigger:
- Github
- GitLab
First, let's create the necessary token and secrets:
-
Go to your desired Slack channel and setup incoming webhooks. Make sure you copy the webhook URL, we will use it in the Github workflow.
-
Go to your Port application, click on the
...
in the top right corner, then clickCredentials
. Copy yourClient ID
andClient secret
.
In the repository where your workflow will reside, create 3 new secrets under Settings -> Secrets and variables -> Actions
:
SLACK_WEBHOOK_URL
- the Slack Webhook URL of the destination channel.PORT_CLIENT_ID
- the client ID you copied from your Port app.PORT_CLIENT_SECRET
- the client secret you copied from your Port app.
Now let's create the workflow file that contains our logic. Under .github/workflows
, create a new file named port-slack-reminder.yml
and use the following snippet as its content:
Github workflow (click to expand)
# port-slack-reminder.yml
name: Generate Scorecards Reminders
on:
workflow_dispatch:
inputs:
runId:
description: 'The id of the action run'
required: true
type: string
jobs:
generate-scorecards-reminders:
runs-on: ubuntu-latest
steps:
- name: Generate Scorecards Reminders
uses: port-labs/port-sender@v0.2.3
with:
operation_kind: scorecard_reminder
port_client_id: ${{ secrets.PORT_CLIENT_ID }}
port_client_secret: ${{ secrets.PORT_CLIENT_SECRET }}
port_region: eu
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
blueprint: service
scorecard: ProductionReadiness
target_kind: slack
- name: Report status to Port
uses: port-labs/port-github-action@v1
with:
clientId: ${{ secrets.PORT_CLIENT_ID }}
clientSecret: ${{ secrets.PORT_CLIENT_SECRET }}
baseUrl: https://api.getport.io
operation: PATCH_RUN
runId: ${{ inputs.runId }}
logMessage: |
Slack reminder sent successfully ๐
This workflow uses Port's Initiatives Sender GitHub Action to send a Slack message.
First, let's create the required webhooks and variables:
-
Go to your desired Slack channel and setup incoming webhooks. Make sure you copy the webhook URL, we will use it in the Github workflow.
-
Go to your Port application, click on the
...
in the top right corner, then clickCredentials
. Copy yourClient ID
andClient secret
.
In the GitLab project where your pipeline will reside, create 3 new variables under Settings->CI/CD->Variables
:
SLACK_WEBHOOK_URL
- the Slack Webhook URL of the destination channel.PORT_CLIENT_ID
- the client ID you copied from your Port app.PORT_CLIENT_SECRET
- the client secret you copied from your Port app.
Create a webhook in GitLab for triggering your GitLab:
- Create a pipeline trigger token;
- Construct the pipeline trigger webhook URL with your project details.
- Back in Port, edit your action and in its
backend
step paste the webhook URL in theEndpoint URL
field.
Now let's create the pipeline file that contains our logic. In your GitLab project create a new file named gitlab-ci.yaml
and use the following snippet as its content:
GitLab pipeline (click to expand)
image: python:3.10.0-alpine
stages:
- fetch-port-access-token
- send_reminders
- post-run-logs
- update-run-status
fetch-port-access-token: # Example - get the Port API access token and RunId
stage: fetch-port-access-token
except:
- pushes
before_script:
- apk update
- apk add jq curl -q
script:
- |
accessToken=$(curl -X POST \
-H 'Content-Type: application/json' \
-d '{"clientId": "'"$PORT_CLIENT_ID"'", "clientSecret": "'"$PORT_CLIENT_SECRET"'"}' \
-s 'https://api.getport.io/v1/auth/access_token' | jq -r '.accessToken')
echo "ACCESS_TOKEN=$accessToken" >> data.env
runId=$(cat $TRIGGER_PAYLOAD | jq -r '.context.runId')
echo "RUN_ID=$runId" >> data.env
artifacts:
reports:
dotenv: data.env
generate-scorecards-reminders:
stage: send_reminders
image: docker:24.0.7
services:
- docker:24.0.7-dind
script:
- image_name="ghcr.io/port-labs/port-sender:$VERSION"
- echo "Generate Scorecards Reminders"
- |
docker run -i --rm --platform="linux/arm64/v8" \
-e INPUT_PORT_CLIENT_ID=$PORT_CLIENT_ID \
-e INPUT_PORT_CLIENT_SECRET=$PORT_CLIENT_SECRET \
-e INPUT_SLACK_WEBHOOK_URL=$SLACK_WEBHOOK_URL \
-e INPUT_OPERATION_KIND="scorecard_reminder" \
-e INPUT_BLUEPRINT="service" \
-e INPUT_SCORECARD="ProductionReadiness" \
-e INPUT_TARGET_KIND="slack" \
$image_name
- echo "Report status to Port"
post-run-logs:
stage: post-run-logs
except:
- pushes
image: curlimages/curl:latest
script:
- |
curl -X POST \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d '{"message": "Slack reminder sent successfully ๐"}' \
"https://api.getport.io/v1/actions/runs/$RUN_ID/logs"
update-run-status:
stage: update-run-status
except:
- pushes
image: curlimages/curl:latest
script:
- |
curl -X PATCH \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-d '{"status":"SUCCESS", "message": {"run_status": "Created Merge Request for '"$bucket_name"' successfully! Merge Request URL: '"$MR_URL"'"}}' \
"https://api.getport.io/v1/actions/runs/$RUN_ID"
variables:
PORT_CLIENT_ID: $PORT_CLIENT_ID
PORT_CLIENT_SECRET: $PORT_CLIENT_SECRET
SLACK_WEBHOOK_URL: $SLACK_WEBHOOK_URL
VERSION: "0.2.3"
The baseUrl
, port_region
, port.baseUrl
, portBaseUrl
, port_base_url
and OCEAN__PORT__BASE_URL
parameters are used to select which instance or Port API will be used.
Port exposes two API instances, one for the EU region of Port, and one for the US region of Port.
- If you use the EU region of Port (https://app.getport.io), your API URL is
https://api.getport.io
. - If you use the US region of Port (https://app.us.getport.io), your API URL is
https://api.us.getport.io
.
All done! The action is ready to be used ๐
Execute the actionโ
After creating an action, it will appear under the Self-service
tab of your Port application:
-
Click on
Create
to begin executing the action. -
Click
Execute
. A small popup will appear, click onView details
:
- This page provides details about the action run. As you can see, the backend returned
Success
and the repo was successfully created:
๐ก Note the Log stream
at the bottom, this can be used to report progress, results and errors. Click here to learn more.
- You can now enter your Slack channel and view the scorecard reminder:
Congratulations! You can now send Slack reminders easily from Port ๐ช๐ฝ
Conclusionโ
Creating scorecards is the first step in setting standards in our development lifecycle. However, to ensure these standards are met, we need to turn rule violations into action items. By automating Slack reminders and the creation of Jira tasks, we can drive change across the entire organization using familiar tools to combine it natively within our delievery lifecycle.