-
Notifications
You must be signed in to change notification settings - Fork 0
feat(actions): add slack-notify, install-yq, install-kustomize #5
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
96db9dd
feat(actions): add slack-notify, install-yq, install-kustomize
vklimontovich eaf48ab
fix(actions): pin yq version + verify sha256
vklimontovich 929305f
feat(slack-notify): add defaults for webhook, color, blocks
vklimontovich 25043ab
feat(slack-notify): add reusable-workflow wrapper, prefer env over input
vklimontovich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| name: Install kustomize | ||
| description: Install the standalone kustomize CLI with a pinned version + sha256 checksum. | ||
|
|
||
| inputs: | ||
| version: | ||
| description: "kustomize version (without leading 'v'), e.g. 5.8.1." | ||
| required: false | ||
| default: "5.8.1" | ||
| sha256: | ||
| description: "Expected sha256 of the linux_amd64 tarball. Lookup at https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv<version>/checksums.txt" | ||
| required: false | ||
| default: "029a7f0f4e1932c52a0476cf02a0fd855c0bb85694b82c338fc648dcb53a819d" | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Install kustomize | ||
| shell: bash | ||
| env: | ||
| VERSION: ${{ inputs.version }} | ||
| SHA256: ${{ inputs.sha256 }} | ||
| run: | | ||
| set -eu | ||
| # Pinned + checksum-verified so a compromised installer script can't | ||
| # silently swap the binary. | ||
| URL="https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv${VERSION}/kustomize_v${VERSION}_linux_amd64.tar.gz" | ||
| curl -fsSL -o /tmp/kustomize.tgz "$URL" | ||
| echo "${SHA256} /tmp/kustomize.tgz" | sha256sum -c - | ||
| tar -xzf /tmp/kustomize.tgz -C /tmp kustomize | ||
| sudo install -m 0755 /tmp/kustomize /usr/local/bin/kustomize | ||
| rm -f /tmp/kustomize.tgz /tmp/kustomize | ||
| kustomize version |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| name: Install yq | ||
| description: Install the yq CLI (mikefarah/yq) with a pinned version + sha256 checksum. | ||
|
|
||
| inputs: | ||
| version: | ||
| description: "yq version (without leading 'v'), e.g. 4.53.2." | ||
| required: false | ||
| default: "4.53.2" | ||
| sha256: | ||
| description: "Expected sha256 of the linux_amd64 binary. Lookup at https://github.com/mikefarah/yq/releases/download/v<version>/checksums (SHA-256 row — see checksums_hashes_order)." | ||
| required: false | ||
| default: "d56bf5c6819e8e696340c312bd70f849dc1678a7cda9c2ad63eebd906371d56b" | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Install yq | ||
| shell: bash | ||
| env: | ||
| VERSION: ${{ inputs.version }} | ||
| SHA256: ${{ inputs.sha256 }} | ||
| run: | | ||
| set -eu | ||
| # Pinned + checksum-verified so a compromised release can't silently swap the binary. | ||
| URL="https://github.com/mikefarah/yq/releases/download/v${VERSION}/yq_linux_amd64" | ||
| curl -fsSL -o /tmp/yq "$URL" | ||
| echo "${SHA256} /tmp/yq" | sha256sum -c - | ||
| sudo install -m 0755 /tmp/yq /usr/local/bin/yq | ||
| rm -f /tmp/yq | ||
| yq --version | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| name: Send Slack Notification | ||
| description: Send a formatted notification to Slack with optional bullet blocks | ||
|
|
||
| inputs: | ||
| slack_webhook_url: | ||
| description: "Slack webhook URL (override). Normally leave empty and set SLACK_WEBHOOK_URL env in the job from secrets.CI_SLACK_WEBHOOK; this input only takes effect if that env var is unset (useful for ad-hoc testing)." | ||
| required: false | ||
| default: "" | ||
| color: | ||
| description: "Attachment color: good, warning, danger, or hex (e.g. #36a64f)." | ||
| required: false | ||
| default: "good" | ||
| header: | ||
| description: "Header text for the notification (required)." | ||
| required: true | ||
| blocks: | ||
| description: "YAML array of block objects with title, value, url (optional), is_code (optional). Omit to send the header alone." | ||
| required: false | ||
| default: "" | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: 🔄 Convert YAML to JSON | ||
| id: convert | ||
| if: ${{ inputs.blocks != '' }} | ||
| shell: bash | ||
| env: | ||
| BLOCKS_YAML: ${{ inputs.blocks }} | ||
| YQ_VERSION: "4.53.2" | ||
| YQ_SHA256: "d56bf5c6819e8e696340c312bd70f849dc1678a7cda9c2ad63eebd906371d56b" | ||
| run: | | ||
| set -eu | ||
| # Pinned + checksum-verified yq install. Keep in sync with .github/actions/install-yq | ||
| # (we inline here so this action stays self-contained for external callers). | ||
| URL="https://github.com/mikefarah/yq/releases/download/v${YQ_VERSION}/yq_linux_amd64" | ||
| curl -fsSL -o /tmp/yq "$URL" | ||
| echo "${YQ_SHA256} /tmp/yq" | sha256sum -c - | ||
| chmod +x /tmp/yq | ||
| BLOCKS_JSON=$(/tmp/yq -o=json '.' <<< "$BLOCKS_YAML") | ||
| echo "blocks_json<<EOF" >> $GITHUB_OUTPUT | ||
| echo "$BLOCKS_JSON" >> $GITHUB_OUTPUT | ||
| echo "EOF" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: 💬 Send Slack notification | ||
| uses: actions/github-script@v9 | ||
| env: | ||
| # Webhook precedence: SLACK_WEBHOOK_URL env var wins (typically set at | ||
| # job level from secrets.CI_SLACK_WEBHOOK — composite actions can't read | ||
| # org secrets directly). The `slack_webhook_url` input is a fallback for | ||
| # ad-hoc testing or direct invocation. | ||
| WEBHOOK_INPUT: ${{ inputs.slack_webhook_url }} | ||
| COLOR: ${{ inputs.color }} | ||
| HEADER: ${{ inputs.header }} | ||
| BLOCKS_JSON: ${{ steps.convert.outputs.blocks_json }} | ||
| with: | ||
| script: | | ||
| const webhook = process.env.SLACK_WEBHOOK_URL || process.env.WEBHOOK_INPUT; | ||
| if (!webhook) { | ||
| throw new Error( | ||
| "slack-notify: no webhook URL. Set SLACK_WEBHOOK_URL env in the " + | ||
| "job (from secrets.CI_SLACK_WEBHOOK) or pass `slack_webhook_url` input." | ||
| ); | ||
| } | ||
|
|
||
| const blocksJson = process.env.BLOCKS_JSON; | ||
| const blocks = blocksJson ? JSON.parse(blocksJson) : []; | ||
|
|
||
| // Build single text with all blocks as bullet points | ||
| const lines = blocks.map(block => { | ||
| let line = `• *${block.title}:* `; | ||
|
|
||
| if (block.is_code) { | ||
| line += `\n\`\`\`${block.value}\`\`\``; | ||
| } else if (block.url) { | ||
| line += `<${block.url}|${block.value}>`; | ||
| } else { | ||
| line += block.value; | ||
| } | ||
|
|
||
| return line; | ||
| }); | ||
|
|
||
| const text = lines.join('\n'); | ||
|
|
||
| // Build complete payload. `text` (top-level) and `fallback` (attachment) drive | ||
| // Slack's notification preview / link-unfurl summary; without them the unfurl | ||
| // shows "[no preview available]". Top-level `text` also renders above the | ||
| // attachment, so we drop the in-attachment header block to avoid duplication. | ||
| const attachment = { | ||
| color: process.env.COLOR, | ||
| fallback: process.env.HEADER, | ||
| }; | ||
| if (text) { | ||
| attachment.blocks = [ | ||
| { type: "section", text: { type: "mrkdwn", text: text } } | ||
| ]; | ||
| } | ||
| const payload = { | ||
| text: process.env.HEADER, | ||
| attachments: [attachment], | ||
| }; | ||
|
|
||
| // Send to Slack | ||
| const response = await fetch(webhook, { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json' | ||
| }, | ||
| body: JSON.stringify(payload) | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| const text = await response.text(); | ||
| throw new Error(`Slack webhook failed: ${response.statusText} - ${text}`); | ||
| } | ||
|
|
||
| console.log('✅ Slack notification sent successfully'); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| name: Slack notify (reusable) | ||
|
|
||
| # Thin wrapper around .github/actions/slack-notify. The composite action can't | ||
| # read org secrets directly, so this reusable workflow pulls | ||
| # secrets.CI_SLACK_WEBHOOK and passes it through. Two use cases: | ||
| # | ||
| # 1. Manual testing of the slack-notify action via the Actions tab | ||
| # (workflow_dispatch). | ||
| # 2. Callers that prefer `secrets: inherit` over setting SLACK_WEBHOOK_URL | ||
| # at job level. Note the trade-off: each call spins up its own runner. | ||
| # For inline notifications inside an existing job, use the composite | ||
| # action directly. | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| header: | ||
| type: string | ||
| required: true | ||
| color: | ||
| type: string | ||
| required: false | ||
| default: "good" | ||
| blocks: | ||
| type: string | ||
| required: false | ||
| default: "" | ||
| workflow_dispatch: | ||
| inputs: | ||
| header: | ||
| type: string | ||
| required: true | ||
| default: "Test notification from slack-notify" | ||
| color: | ||
| type: string | ||
| required: false | ||
| default: "good" | ||
| blocks: | ||
| type: string | ||
| required: false | ||
| default: "" | ||
|
|
||
| jobs: | ||
| send: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| # Composite action is pinned to @main — `actions/checkout` in a reusable | ||
| # workflow checks out the *caller's* repo, so we can't use a `./` path | ||
| # without an extra clone of jitsucom/github-workflows. If this wrapper | ||
| # ever ships in tagged releases, bump this @ref alongside the tag. | ||
| - uses: jitsucom/github-workflows/.github/actions/slack-notify@main | ||
| env: | ||
| SLACK_WEBHOOK_URL: ${{ secrets.CI_SLACK_WEBHOOK }} | ||
| with: | ||
| header: ${{ inputs.header }} | ||
| color: ${{ inputs.color }} | ||
| blocks: ${{ inputs.blocks }} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.