Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 6 additions & 48 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ jobs:
token: ${{ secrets.PAT_TOKEN }}

- name: CFDI dependencies
id: cfdi
uses: ./.github/actions/cfdi
with:
token: ${{ secrets.PAT_TOKEN }}
Expand All @@ -52,63 +51,22 @@ jobs:

- name: Publish (main)
if: steps.branch.outputs.is_main == 'true'
run: |
SCOPES='${{ steps.cfdi.outputs.scopes }}'

# --- Fase 1: Bump de TODOS los scopes ---
echo "========== PHASE 1: VERSION BUMP =========="
for scope in $(echo "$SCOPES" | jq -r '.[]'); do
echo "=== Bumping $scope ==="
rush version --version-policy "$scope" --bump
done

# --- Fase 2: Un solo publish (Rush maneja orden topológico) ---
echo "========== PHASE 2: PUBLISH =========="
if rush publish -p -b main --set-access-level=public; then
git add -A
echo "✓ Publish exitoso"
else
echo "::error::Publish falló"
exit 1
fi
run: rush publish -p -b main --include-all --set-access-level=public

- name: Publish (prerelease)
if: steps.branch.outputs.is_main == 'false'
run: |
TAG="${{ steps.branch.outputs.name }}"
SCOPES='${{ steps.cfdi.outputs.scopes }}'

# --- Fase 1: Bump de TODOS los scopes ---
echo "========== PHASE 1: VERSION BUMP =========="
for scope in $(echo "$SCOPES" | jq -r '.[]'); do
echo "=== Bumping $scope ==="
rush version --version-policy "$scope" --bump --override-bump prerelease --override-prerelease-id "$TAG"
done

# --- Fase 2: Un solo publish (Rush maneja orden topológico) ---
echo "========== PHASE 2: PUBLISH =========="
if rush publish --publish --tag "$TAG" --set-access-level=public --apply; then
git add -A
echo "✓ Publish exitoso"
else
echo "::error::Publish falló"
exit 1
fi
run: rush publish --publish --tag ${{ steps.branch.outputs.name }} --include-all --set-access-level=public --apply

- name: Commit version bumps
run: |
BRANCH="${{ steps.branch.outputs.name }}"
git add -A
if [ -n "$(git diff --cached --name-only)" ]; then
if [ "$BRANCH" = "main" ]; then
git commit -m "chore: release $(date +%Y-%m-%d)"
else
git commit -m "chore: prerelease $BRANCH $(date +%Y-%m-%d)"
fi
git push origin $BRANCH
if [ "$BRANCH" = "main" ]; then
git commit -m "chore: release $(date +%Y-%m-%d)" || echo "No changes to commit"
else
echo "No changes to commit"
git commit -m "chore: prerelease $BRANCH $(date +%Y-%m-%d)" || echo "No changes to commit"
fi
git push origin $BRANCH

- name: Create GitHub Releases
run: node common/scripts/github-release.js
Expand Down
110 changes: 1 addition & 109 deletions common/config/rush/version-policies.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 43 additions & 13 deletions common/scripts/github-actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@

async function execa(command, params) {
const { spawn } = require('child_process');
const child = spawn(command, params);

let data = '';
for await (const chunk of child.stdout) {
//console.log('stdout chunk: ' + chunk);
data += chunk;
}
let error = '';
for await (const chunk of child.stderr) {
//console.error('stderr chunk: ' + chunk);
error += chunk;
}
const exitCode = await new Promise((resolve, reject) => {
child.on('close', resolve);
});

if (exitCode) {
throw new Error(`subprocess error exit ${exitCode}, ${error}`);
}
return data;
}
function getDependences(scope) {
const dependencies = {
xml: {
Expand Down Expand Up @@ -178,6 +201,7 @@ module.exports = async ({ github, context, core }) => {
console.log("branch:", branch);
console.log("eventName:", context.eventName);

const branchs = ['next','beta', 'alpha','dev']
const eventName = context.eventName
let commits = context.payload.commits || [];

Expand All @@ -195,18 +219,24 @@ module.exports = async ({ github, context, core }) => {
commits = commits_local.map(({commit})=>commit)
}
const scopes = getScopes(commits);
console.log("scopes from commits", scopes);

// Filtrar scopes que no tienen shouldPublish: true
const rushJson = JSON.parse(require('fs').readFileSync('./rush.json', 'utf8'));
const publishablePolicies = new Set(
rushJson.projects
.filter(p => p.shouldPublish && p.versionPolicyName)
.map(p => p.versionPolicyName)
);
const filteredScopes = scopes.filter(s => publishablePolicies.has(s));
console.log("publishable scopes", filteredScopes);
console.log("commits", scopes);

core.setOutput('scopes', JSON.stringify(filteredScopes));
core.setOutput('branch', branch);
for (var i = 0; i < scopes.length; i++) {
const scope = scopes[i];
const comands = [
'version',
'--version-policy',
scope,
'--bump',
]
if (branchs.includes(branch)) {
comands.push('--override-bump');
comands.push('prerelease');
comands.push('--override-prerelease-id');
comands.push(branch);
}
console.log(comands);
const data = await execa('rush', comands);
console.log(data);
}
};
Loading
Loading