Skip to content

[SDK Suppressions labels] Add new action to update suppressions labels #8

[SDK Suppressions labels] Add new action to update suppressions labels

[SDK Suppressions labels] Add new action to update suppressions labels #8

name: SDK Suppressions
on:
pull_request:
branches:
- main
- RPSaaSMaster
- release*
- jacktn/suppression-action
jobs:
process-sdk-suppressions-labels:
name: Sdk Suppressions
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# Required since "HEAD^" is passed to Get-ChangedFiles
fetch-depth: 2
- name: Setup Node and run `npm ci`
uses: ./.github/actions/setup-node-npm-ci
- name: Get GitHub PullRequest Changed Files
shell: pwsh
id: get-changedFiles
run: |
. eng/scripts/ChangedFiles-Functions.ps1
$changedFiles = @(Get-ChangedFiles)
echo "PR Changed files: $changedFiles"
Add-Content -Path $env:GITHUB_OUTPUT -Value "changedFiles=$changedFiles"
- name: Get GitHub PullRequest Context
uses: actions/github-script@v7
id: fetch-pullRequest-context
with:
script: |
const pr = context.payload.pull_request;
if (!pr) {
throw new Error("This workflow must run in the context of a pull request.");
}
console.log("This action trigger by ", context.eventName);
const prContext = {
number: pr.number,
title: pr.title,
html_url: pr.html_url,
labels: pr.labels.map(label => label.name)
};
const prContextStr = JSON.stringify(prContext);
console.log("PR Context:", prContextStr);
core.setOutput("prContext", prContextStr);
core.setOutput("prLabels", pr.labels.map(label => label.name));
result-encoding: string
- name: Run Get suppressions label script
id: run-suppressions-script
env:
GITHUB_PULL_REQUEST_CONTEXT: ${{ steps.fetch-pullRequest-context.outputs.prContext }}
OUTPUT_FILE: "output.json"
GITHUB_PULL_REQUEST_CHANGE_FILES: ${{ steps.get-changedFiles.outputs.changedFiles }}
GITHUB_PULL_REQUEST_LABELS: ${{ steps.fetch-pullRequest-context.outputs.prLabels }}
run: |
node eng/tools/sdk-suppressions/cmd/sdk-suppressions-label.js HEAD^ HEAD $GITHUB_PULL_REQUEST_CHANGE_FILES $GITHUB_PULL_REQUEST_LABELS
OUTPUT=$(cat $OUTPUT_FILE)
echo "Script output labels: $OUTPUT"
labelsToAdd=$(echo "$OUTPUT" | sed -n 's/.*"labelsToAdd":\[\([^]]*\)\].*/\1/p' | tr -d '" ')
labelsToRemove=$(echo "$OUTPUT" | sed -n 's/.*"labelsToRemove":\[\([^]]*\)\].*/\1/p' | tr -d '" ')
for label in $(echo $labelsToAdd | tr ',' '\n'); do
echo "Label to add: $label"
echo "$label=true" >> $GITHUB_OUTPUT
done
for label in $(echo $labelsToRemove | tr ',' '\n'); do
echo "Label to remove: $label"
echo "$label=false" >> $GITHUB_OUTPUT
done
- uses: ./.github/actions/add-label-artifact
name: Upload artifact with results-go
if: ${{ steps.run-suppressions-script.outputs.BreakingChange-Go-Sdk-Suppression }}
with:
name: "BreakingChange-Go-Sdk-Suppression"
value: "${{ steps.run-suppressions-script.outputs.BreakingChange-Go-Sdk-Suppression == 'true' }}"
- uses: ./.github/actions/add-label-artifact
name: Upload artifact with results java
if: ${{ steps.run-suppressions-script.outputs.BreakingChange-Java-Sdk-Suppression }}
with:
name: "BreakingChange-Java-Sdk-Suppression"
value: "${{ steps.run-suppressions-script.outputs.BreakingChange-Java-Sdk-Suppression == 'true' }}"
- uses: ./.github/actions/add-label-artifact
name: Upload artifact with results js
if: ${{ steps.run-suppressions-script.outputs.BreakingChange-JavaScript-Sdk-Suppression }}
with:
name: "BreakingChange-JavaScript-Sdk-Suppression"
value: "${{ steps.run-suppressions-script.outputs.BreakingChange-JavaScript-Sdk-Suppression == 'true' }}"
- uses: ./.github/actions/add-label-artifact
name: Upload artifact with results python
if: ${{ steps.run-suppressions-script.outputs.BreakingChange-Python-Sdk-Suppression }}
with:
name: "BreakingChange-Python-Sdk-Suppression"
value: "${{ steps.run-suppressions-script.outputs.BreakingChange-Python-Sdk-Suppression == 'true' }}"