build(deps): bump tj-actions/changed-files from 44.5.2 to 45.0.1 #157
Workflow file for this run
This file contains 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
name: 'CI/test and prepare release' | |
concurrency: | |
group: ${{ github.head_ref }} | |
cancel-in-progress: true | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened, labeled] | |
pull_request_target: | |
types: [closed] | |
jobs: | |
detect: | |
runs-on: ubuntu-latest | |
name: 'Detect pull request context' | |
outputs: | |
directories: ${{ steps.condense.outputs.result }} | |
release-type: ${{ steps.check_pr_label.outputs.release-type}} | |
is-merge-event: >- | |
${{ github.event_name == 'pull_request_target' | |
&& github.event.action == 'closed' | |
&& github.event.pull_request.merged == true }} | |
steps: | |
- name: Check PR labels | |
id: check_pr_label | |
env: | |
PR_URL: ${{github.event.pull_request.html_url}} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
LABELS=$(gh pr view $PR_URL --json labels --jq '.labels[]| select((.name=="minor") or (.name=="major") or (.name=="patch") or (.name=="no-release")) |.name') | |
NUMBER_OF_LABELS=$(echo "$LABELS" |wc -w) | |
if [ "$NUMBER_OF_LABELS" -eq "1" ] ; then | |
echo "Found: $LABELS" | |
echo "release-type=$LABELS" >> $GITHUB_OUTPUT | |
elif [ "$NUMBER_OF_LABELS" -gt "1" ] ; then | |
echo "::error ::Too many release type labels: $( echo $LABELS | tr '\n' ' ' )" | |
exit 1 | |
else | |
echo "::error ::No release type labels found(patch/minor/major/no-release)" | |
exit 2 | |
fi | |
- name: Get all changed files | |
id: raw-files | |
uses: tj-actions/[email protected] | |
with: | |
json: true | |
escape_json: false | |
- name: Condense to directory list | |
uses: actions/github-script@v7 | |
id: condense | |
env: | |
RAW_FILES: '${{ steps.raw-files.outputs.all_modified_files }}' | |
with: | |
script: | | |
const raw = JSON.parse(process.env.RAW_FILES); | |
const directories = Array.from(new Set(raw | |
.filter(x => !x.startsWith('.')) | |
.filter(x => x.includes('/')) | |
.map(x => x.split('/')[0]) | |
)); | |
if (directories.length < 1) return {}; | |
return { | |
include: directories.map(directory => ({ directory })), | |
}; | |
validate: | |
needs: detect | |
if: ${{ needs.detect.outputs.directories != '{}' && github.event.action != 'closed' }} | |
strategy: | |
matrix: "${{ fromJson(needs.detect.outputs.directories) }}" | |
fail-fast: false | |
uses: ./.github/workflows/reusable-validate.yaml | |
with: | |
terraformVersion: '1.7.4' | |
moduleRootDirectory: ${{ matrix.directory }} | |
secrets: | |
appId: ${{ secrets.appId }} | |
appPrivateKey: ${{ secrets.appPrivateKey }} | |
lint: | |
needs: detect | |
if: ${{ needs.detect.outputs.directories != '{}' && github.event.action != 'closed' }} | |
strategy: | |
matrix: "${{ fromJson(needs.detect.outputs.directories) }}" | |
fail-fast: false | |
uses: ./.github/workflows/reusable-lint.yaml | |
with: | |
moduleRootDirectory: ${{ matrix.directory }} | |
tflintVersion: 'v0.50.3' | |
secrets: | |
githubToken: ${{ secrets.GITHUB_TOKEN }} | |
analysis: | |
needs: detect | |
if: ${{ needs.detect.outputs.directories != '{}' && github.event.action != 'closed' }} | |
strategy: | |
matrix: "${{ fromJson(needs.detect.outputs.directories) }}" | |
fail-fast: false | |
uses: ./.github/workflows/reusable-analysis.yaml | |
with: | |
moduleRootDirectory: ${{ matrix.directory }} | |
secrets: | |
githubToken: ${{ secrets.GITHUB_TOKEN }} | |
plan: | |
needs: detect | |
if: ${{ needs.detect.outputs.directories != '{}' && ( needs.detect.outputs.is-merge-event == 'true' || github.event.action != 'closed' )}} | |
strategy: | |
matrix: "${{ fromJson(needs.detect.outputs.directories) }}" | |
fail-fast: false | |
uses: ./.github/workflows/reusable-plan.yaml | |
with: | |
moduleRootDirectory: ${{ matrix.directory }} | |
releaseType: ${{ needs.detect.outputs.release-type }} | |
secrets: | |
githubToken: ${{ secrets.GITHUB_TOKEN }} | |
comment: | |
needs: [detect, plan] | |
if: github.event.action != 'closed' | |
runs-on: ubuntu-latest | |
name: 'Comment on PR' | |
steps: | |
- uses: actions/download-artifact@v4 | |
with: | |
path: outputs | |
- name: Display structure of downloaded files | |
run: ls -R | |
working-directory: outputs | |
- uses: actions/github-script@v7 | |
with: | |
script: | | |
const { owner, repo } = context.repo; | |
const { number: issue_number } = context.issue; | |
const { readdir, readFile } = require('fs').promises; | |
const utf8 = { encoding: 'utf-8' }; | |
const lines = [ | |
'# Release plan', '', | |
'| Directory | Previous version | New version |', | |
'|--|--|--|', | |
]; | |
const sections = []; | |
for (const folder of await readdir('outputs', { withFileTypes: true })) { | |
if (!folder.isDirectory()) continue; | |
const readText = (name) => readFile(name, utf8).then(x => x.trim()); | |
lines.push('| '+[ | |
`\`${folder.name}\``, | |
`${await readText(`outputs/${folder.name}/previous-version.txt`)}`, | |
`**${await readText(`outputs/${folder.name}/new-version.txt`)}**`, | |
].join(' | ')+' |'); | |
sections.push(`<details><summary>Changelog preview: ${folder.name}</summary>\n\n${await readText(`outputs/${folder.name}/changelog.md`)}\n</details>`); | |
} | |
const finalBody = [lines.join('\n'), ...sections].join('\n\n'); | |
const {data: allComments} = await github.rest.issues.listComments({ issue_number, owner, repo }); | |
const ourComments = allComments | |
.filter(comment => comment.user.login === 'github-actions[bot]') | |
.filter(comment => comment.body.startsWith(lines[0]+'\n')); | |
const latestComment = ourComments.slice(-1)[0]; | |
if (latestComment && latestComment.body === finalBody) { | |
console.log('Existing comment is already up to date.'); | |
return; | |
} | |
const {data: newComment} = await github.rest.issues.createComment({ issue_number, owner, repo, body: finalBody }); | |
console.log('Posted comment', newComment.id, '@', newComment.html_url); | |
// Delete all our previous comments | |
for (const comment of ourComments) { | |
if (comment.id === newComment.id) continue; | |
console.log('Deleting previous PR comment from', comment.created_at); | |
await github.rest.issues.deleteComment({ comment_id: comment.id, owner, repo }); | |
} | |
trigger-release: | |
needs: [detect, plan] | |
if: needs.detect.outputs.is-merge-event == 'true' | |
runs-on: ubuntu-latest | |
name: 'Dispatch release event' | |
steps: | |
- uses: actions/download-artifact@v4 | |
with: | |
path: outputs | |
- name: Combine version information | |
id: extract-releases | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const { readdir, readFile } = require('fs').promises; | |
const utf8 = { encoding: 'utf-8' }; | |
const readText = (name) => readFile(name, utf8).then(x => x.trim()); | |
const directories = await readdir('outputs', { withFileTypes: true }); | |
return await Promise.all(directories | |
.filter(x => x.isDirectory()) | |
.map(async folder => ({ | |
module: folder.name, | |
prevVersion: await readText(`outputs/${folder.name}/previous-version.txt`), | |
newVersion: await readText(`outputs/${folder.name}/new-version.txt`), | |
}))); | |
- name: Dispatch monorepo_release event | |
uses: actions/github-script@v7 | |
env: | |
RELEASE_LIST: '${{ steps.extract-releases.outputs.result }}' | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const payload = { | |
run_id: "${{ github.run_id }}", | |
sha: context.sha, | |
releases: JSON.parse(process.env.RELEASE_LIST), | |
}; | |
console.log('Event payload:', JSON.stringify(payload, null, 2)); | |
const { owner, repo } = context.repo; | |
await github.rest.repos.createDispatchEvent({ | |
owner, repo, | |
event_type: 'monorepo_release', | |
client_payload: payload, | |
}); |