Skip to content

chore: Refactor build workflow to handle multiple commits and check f… #26

chore: Refactor build workflow to handle multiple commits and check f…

chore: Refactor build workflow to handle multiple commits and check f… #26

Workflow file for this run

name: Ruff and Publish
on:
push:
branches:
- "**"
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Ruff Linter
uses: chartboost/ruff-action@v1
publish:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' # Executes only for pushes to the main branch
needs: lint
steps:
- uses: actions/checkout@v4
- name: Check for version change in pyproject.toml
id: check_version
uses: actions/github-script@v6
with:
script: |
const payload = context.payload;
let changedFiles = [];
for (const commit of payload.commits) {
if (commit.modified) changedFiles = changedFiles.concat(commit.modified);
if (commit.added) changedFiles = changedFiles.concat(commit.added);
if (commit.removed) changedFiles = changedFiles.concat(commit.removed);
}
const isVersionChanged = changedFiles.includes('pyproject.toml');
if (!isVersionChanged) {
console.log("No change in pyproject.toml");
return false;
}
const fs = require('fs');
const content = fs.readFileSync('./pyproject.toml', 'utf8');
const versionRegex = /version = "(\S+)"/;
const match = versionRegex.exec(content);
if (match) {
core.setOutput('new_version', match[1]);
console.log(`Version changed to ${match[1]}`);
return true;
} else {
console.log("Version line not found or unchanged");
return false;
}
result-encoding: string