Update dependency @jakubmazanec/eslint-config to ^4.1.5 #503
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
# | |
# DO NOT EDIT! | |
# This file was autogenerated by Carson. | |
# Changes may cause incorrect behavior and will be lost when the file is regenerated. | |
# | |
# Run `npx carson update workspace` to regenerate. | |
# | |
name: Update pull request | |
on: | |
pull_request_target: | |
branches: [development] | |
jobs: | |
update_pull_request: | |
name: Update pull request | |
if: ${{ github.actor == 'renovate[bot]' && contains(github.head_ref, 'renovate/') }} | |
runs-on: ubuntu-latest | |
timeout-minutes: 15 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.head_ref }} | |
token: ${{ secrets.PAT }} | |
fetch-depth: 0 | |
- name: Configure git | |
run: | | |
git config user.email "bot@mazanec.dev" | |
git config user.name "Bot" | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
- name: Install packages | |
run: npm ci | |
- name: Generate changeset | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
let {promises: fs} = require('node:fs'); | |
let path = require('node:path'); | |
let semver = require('semver'); | |
let _ = require('lodash'); | |
async function checkCarsonTemplatesPackage(dependencyBumps) { | |
if (true) { | |
return false; | |
} | |
let constantsFilePath = '/source/constants.ts'; | |
let constantsFile = await fs.readFile(constantsFilePath, 'utf8'); | |
for (let [dependencyName, bump] of dependencyBumps) { | |
let regexp = new RegExp(`(?<=('${_.escapeRegExp(dependencyName)}'|${_.escapeRegExp(dependencyName)}):\\s+')\\^\\d+\\.\\d+\\.\\d+(?='.*$)`, 'mi'); | |
let result = regexp.exec(constantsFile); | |
if (result) { | |
let newMajorVersion = semver.major(semver.minVersion(bump)); | |
let oldMajorVersion = semver.major(semver.minVersion(result[0])); | |
if (newMajorVersion > oldMajorVersion || dependencyName === 'node') { // Node.js is a special case, because it isn't specified in `dependencies` field | |
throw new Error(`Bumping major version of dependency "${dependencyName}" that is handled by Carson, update of the Carson template package is needed!`); | |
} | |
} | |
} | |
return; | |
} | |
async function getProjects(files) { | |
let names = []; | |
for (let file of files) { | |
let packageJson = JSON.parse(await fs.readFile(file, 'utf8')); | |
names.push(packageJson.name); | |
} | |
return names; | |
} | |
async function createChangeset(fileName, dependencyBumps, projects) { | |
let message = ''; | |
for (let [dependencyName, bump] of dependencyBumps) { | |
message = message + `Dependency \`${dependencyName}\` updated to version \`${bump}\`.\n`; | |
} | |
message = message.replace('\n', ' '); | |
let header = projects.map((projectName) => `'${projectName}': patch`).join('\n'); | |
await fs.writeFile(fileName, `---\n${header}\n---\n${message.trim()}\n`); | |
} | |
async function createChangesetForCarsonTemplates(fileName, dependencyBumps, projects) { | |
let message = ''; | |
for (let [dependencyName, bump] of dependencyBumps) { | |
message = message + `Applies templates from \`${dependencyName}\` updated to version \`${bump}\`.\n`; | |
} | |
message = message.replace('\n', ' '); | |
let header = projects.map((projectName) => `'${projectName}': patch`).join('\n'); | |
await fs.writeFile(fileName, `---\n${header}\n---\n${message.trim()}\n`); | |
} | |
async function getBumps(files) { | |
let bumps = new Map(); | |
for (let file of files) { | |
let {stdout: changes} = await exec.getExecOutput('git', ['show', file]); | |
for (let change of changes.split('\n')) { | |
if (!change.startsWith('+ ')) { | |
continue; | |
} | |
let match = change.match(/"(.*?)"/g); | |
bumps.set(match[0].replace(/"/g, ''), match[1].replace(/"/g, '')); | |
} | |
} | |
return bumps; | |
} | |
async function getProjectsUsingCarsonTemplates(dir = process.cwd(), result = []) { | |
let entries = await fs.readdir(dir, {withFileTypes: true}); | |
for (let entry of entries) { | |
let fullPath = path.join(dir, entry.name); | |
if (entry.isDirectory()) { | |
if (entry.name === '.carson' && dir !== process.cwd()) { | |
let packageJson = JSON.parse(await fs.readFile(path.join(dir, 'package.json'), 'utf8')); | |
result.push(packageJson.name); | |
} else { | |
await getProjectsUsingCarsonTemplates(fullPath, result); | |
} | |
} | |
} | |
return result; | |
} | |
let diffOutput = await exec.getExecOutput('git diff --name-only HEAD~1'); | |
let diffFiles = diffOutput.stdout.split('\n'); | |
if (diffFiles.find((diffFile) => diffFile.startsWith('.changeset'))) { | |
console.log('Changeset already exists, skipping...'); | |
return; | |
} | |
let files = diffFiles | |
.filter((file) => file !== 'package.json') // skip workspace package.json | |
.filter((file) => file.includes('package.json')); | |
let filesWithWorkspace = diffFiles | |
.filter((file) => file.includes('package.json')); | |
let {stdout: shortHash} = await exec.getExecOutput('git rev-parse --short HEAD'); | |
let changesetName = `.changeset/renovate-${shortHash.trim()}.md`; | |
let updatedProjects = await getProjects(files); | |
let dependencyBumpsWithWorkspace = await getBumps(filesWithWorkspace); | |
await checkCarsonTemplatesPackage(dependencyBumpsWithWorkspace); | |
if ( | |
!updatedProjects.length && dependencyBumpsWithWorkspace.has('@jakubmazanec/carson-templates') | |
) { | |
updatedProjects = await getProjectsUsingCarsonTemplates(); | |
let dependencyBumps = await getBumps(filesWithWorkspace); | |
await createChangesetForCarsonTemplates(changesetName, dependencyBumps, updatedProjects); | |
return; | |
} else if (!updatedProjects.length) { | |
console.log('No package.json changes to published packages, skipping...'); | |
await exec.exec('npx', ['changeset', '--empty']); | |
return; | |
} | |
let dependencyBumps = await getBumps(files); | |
await createChangeset(changesetName, dependencyBumps, updatedProjects); | |
- name: Update Carson | |
run: | | |
npm install | |
- name: Commit and push changes | |
run: | | |
git add . --all | |
git commit -m"Update" | |
git push --force |