Skip to content

Commit

Permalink
Update workflow files
Browse files Browse the repository at this point in the history
- Use the latest action versions
- Disable Slack notification for Dependabot runs
- Replace edge/simple-slack-notify
  • Loading branch information
martijngastkemper committed Feb 23, 2024
1 parent c14deba commit 82dcbfd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
53 changes: 36 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,54 @@ on:
jobs:
ci:
name: CI
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "10.x"
cache: "yarn"
cache-dependency-path: yarn.lock
- run: yarn install
- run: yarn run lint
- run: yarn run test

notification:
name: Slack notification
runs-on: ubuntu-20.04
if: always()
runs-on: ubuntu-latest
if: ${{ always() && github.actor != 'dependabot[bot]' }}
needs: [ci]

env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

steps:
- name: Send notification
uses: edge/simple-slack-notify@master
with:
channel: "#ci"
username: CI
status: ${{ (contains(needs.*.result, 'cancelled') && 'cancelled') || (contains(needs.*.result, 'failure') && 'failure') || 'success' }}
success_text: ":octocat: <${env.GITHUB_SERVER_URL}/${env.GITHUB_REPOSITORY}/actions/runs/${env.GITHUB_RUN_ID}|Build #${env.GITHUB_RUN_NUMBER}> of *${env.GITHUB_REPOSITORY}@${{ github.ref_name }}* by *${env.GITHUB_ACTOR}* completed successfully."
failure_text: ":octocat: <${env.GITHUB_SERVER_URL}/${env.GITHUB_REPOSITORY}/actions/runs/${env.GITHUB_RUN_ID}|Build #${env.GITHUB_RUN_NUMBER}> of *${env.GITHUB_REPOSITORY}@${{ github.ref_name }}* by *${env.GITHUB_ACTOR}* failed."
cancelled_text: ":octocat: <${env.GITHUB_SERVER_URL}/${env.GITHUB_REPOSITORY}/actions/runs/${env.GITHUB_RUN_ID}|Build #${env.GITHUB_RUN_NUMBER}> of *${env.GITHUB_REPOSITORY}@${{ github.ref_name }}* by *${env.GITHUB_ACTOR}* was cancelled."
run: |
# Steps to setup this job:
# 1. Copy this job to your workflow file.
# 2. Add all the jobs after which the notification must be send to `needs`.
# 3. For sending notifications to #CI channel you're now done.
# Optionally: Change the message `successText`, `failureText` and `cancelledText` to your needs.
#
# To send notification to another channel:
# 1. Create a webhook url in the Slack app: https://api.slack.com/apps/A04DZLM3C78
# 2. Add the URL to the repository secrets with the name `SLACK_WEBHOOK_URL`.
# 3. Swap the `webhookUrl` variables.
#
webhookUrl="${{ secrets.SLACK_WEBHOOK_URL }}"
successText=":octocat: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Build #${{ github.run_number }}> of *${{ github.repository }}@${{ github.ref_name }}* by *${{ github.actor }}* completed successfully."
failureText=":octocat: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Build #${{ github.run_number }}> of *${{ github.repository }}@${{ github.ref_name }}* by *${{ github.actor }}* failed."
cancelledText=":octocat: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Build #${{ github.run_number }}> of *${{ github.repository }}@${{ github.ref_name }}* by *${{ github.actor }}* was cancelled.😥"
status="${{ (contains(needs.*.result, 'cancelled') && 'cancelled') || (contains(needs.*.result, 'failure') && 'failure') || 'success' }}"
if [ "$status" = 'success' ]; then
color='good'
text=$successText
elif [ "$status" = 'failure' ]; then
color='danger'
text=$failureText
elif [ "$status" = "cancelled" ]; then
color='warning'
text=$cancelledText
fi
curl "$webhookUrl" -X "POST" --header "Content-Type: application/json" \
--data "{attachments: [{text: \"$text\", color: \"$color\"}]}"
5 changes: 2 additions & 3 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
on: push
name: validate commit message action
name: Validate commit message
jobs:
build:
name: harmenjanssen/commit-message-validation-action@master
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: harmenjanssen/commit-message-validation-action@master
- name: Validate
uses: harmenjanssen/commit-message-validation-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 82dcbfd

Please sign in to comment.