Skip to content

.github/workflows/trusted.yml #8

.github/workflows/trusted.yml

.github/workflows/trusted.yml #8

Workflow file for this run

on:
workflow_run:
workflows: ["apidiff"]
types:
- completed
permissions:
pull-requests: write
jobs:
tag-breaking-change:
name: Tag breaking changes
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'workflow_run'
steps:
- name: 'Download artifact'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: artifacts } = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
const matchArtifact = artifacts.find(artifact => artifact.name === 'apidiff');
if (!matchArtifact) {
throw new Error('No matching artifact found');
}
const { data: artifactZip } = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
const fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/apidiff.zip`, Buffer.from(artifactZip));
- name: 'Unzip artifact'
run: unzip apidiff.zip
- name: 'Add or remove label'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const jsonData = JSON.parse(fs.readFileSync('apidiff.json', 'utf8'));
const issueNumber = jsonData.id;
const semverType = jsonData['semver-type'];
if (semverType === 'major') {
// Add 'breaking-change' label
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: ['breaking-change'],
});
} else {
// Remove 'breaking-change' label if it exists
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
name: 'breaking-change',
});
} catch (error) {
console.log('Label breaking-change not found or already removed');
}
}