Skip to content

Commit eecda03

Browse files
authored
Merge pull request #83 from MisaelMa/fix/publish-sort
Fix/publish sort
2 parents 07c6405 + 51acc05 commit eecda03

4 files changed

Lines changed: 49 additions & 187 deletions

File tree

.github/workflows/publish.yml

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ jobs:
2525
token: ${{ secrets.PAT_TOKEN }}
2626

2727
- name: CFDI dependencies
28-
id: cfdi
2928
uses: ./.github/actions/cfdi
3029
with:
3130
token: ${{ secrets.PAT_TOKEN }}
@@ -52,63 +51,22 @@ jobs:
5251

5352
- name: Publish (main)
5453
if: steps.branch.outputs.is_main == 'true'
55-
run: |
56-
SCOPES='${{ steps.cfdi.outputs.scopes }}'
57-
58-
# --- Fase 1: Bump de TODOS los scopes ---
59-
echo "========== PHASE 1: VERSION BUMP =========="
60-
for scope in $(echo "$SCOPES" | jq -r '.[]'); do
61-
echo "=== Bumping $scope ==="
62-
rush version --version-policy "$scope" --bump
63-
done
64-
65-
# --- Fase 2: Un solo publish (Rush maneja orden topológico) ---
66-
echo "========== PHASE 2: PUBLISH =========="
67-
if rush publish -p -b main --set-access-level=public; then
68-
git add -A
69-
echo "✓ Publish exitoso"
70-
else
71-
echo "::error::Publish falló"
72-
exit 1
73-
fi
54+
run: rush publish -p -b main --include-all --set-access-level=public
7455

7556
- name: Publish (prerelease)
7657
if: steps.branch.outputs.is_main == 'false'
77-
run: |
78-
TAG="${{ steps.branch.outputs.name }}"
79-
SCOPES='${{ steps.cfdi.outputs.scopes }}'
80-
81-
# --- Fase 1: Bump de TODOS los scopes ---
82-
echo "========== PHASE 1: VERSION BUMP =========="
83-
for scope in $(echo "$SCOPES" | jq -r '.[]'); do
84-
echo "=== Bumping $scope ==="
85-
rush version --version-policy "$scope" --bump --override-bump prerelease --override-prerelease-id "$TAG"
86-
done
87-
88-
# --- Fase 2: Un solo publish (Rush maneja orden topológico) ---
89-
echo "========== PHASE 2: PUBLISH =========="
90-
if rush publish --publish --tag "$TAG" --set-access-level=public --apply; then
91-
git add -A
92-
echo "✓ Publish exitoso"
93-
else
94-
echo "::error::Publish falló"
95-
exit 1
96-
fi
58+
run: rush publish --publish --tag ${{ steps.branch.outputs.name }} --include-all --set-access-level=public --apply
9759

9860
- name: Commit version bumps
9961
run: |
10062
BRANCH="${{ steps.branch.outputs.name }}"
10163
git add -A
102-
if [ -n "$(git diff --cached --name-only)" ]; then
103-
if [ "$BRANCH" = "main" ]; then
104-
git commit -m "chore: release $(date +%Y-%m-%d)"
105-
else
106-
git commit -m "chore: prerelease $BRANCH $(date +%Y-%m-%d)"
107-
fi
108-
git push origin $BRANCH
64+
if [ "$BRANCH" = "main" ]; then
65+
git commit -m "chore: release $(date +%Y-%m-%d)" || echo "No changes to commit"
10966
else
110-
echo "No changes to commit"
67+
git commit -m "chore: prerelease $BRANCH $(date +%Y-%m-%d)" || echo "No changes to commit"
11168
fi
69+
git push origin $BRANCH
11270
11371
- name: Create GitHub Releases
11472
run: node common/scripts/github-release.js

common/config/rush/version-policies.json

Lines changed: 0 additions & 108 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/scripts/github-actions.js

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
11

2+
async function execa(command, params) {
3+
const { spawn } = require('child_process');
4+
const child = spawn(command, params);
5+
6+
let data = '';
7+
for await (const chunk of child.stdout) {
8+
//console.log('stdout chunk: ' + chunk);
9+
data += chunk;
10+
}
11+
let error = '';
12+
for await (const chunk of child.stderr) {
13+
//console.error('stderr chunk: ' + chunk);
14+
error += chunk;
15+
}
16+
const exitCode = await new Promise((resolve, reject) => {
17+
child.on('close', resolve);
18+
});
19+
20+
if (exitCode) {
21+
throw new Error(`subprocess error exit ${exitCode}, ${error}`);
22+
}
23+
return data;
24+
}
225
function getDependences(scope) {
326
const dependencies = {
427
xml: {
@@ -178,6 +201,7 @@ module.exports = async ({ github, context, core }) => {
178201
console.log("branch:", branch);
179202
console.log("eventName:", context.eventName);
180203

204+
const branchs = ['next','beta', 'alpha','dev']
181205
const eventName = context.eventName
182206
let commits = context.payload.commits || [];
183207

@@ -195,18 +219,24 @@ module.exports = async ({ github, context, core }) => {
195219
commits = commits_local.map(({commit})=>commit)
196220
}
197221
const scopes = getScopes(commits);
198-
console.log("scopes from commits", scopes);
199-
200-
// Filtrar scopes que no tienen shouldPublish: true
201-
const rushJson = JSON.parse(require('fs').readFileSync('./rush.json', 'utf8'));
202-
const publishablePolicies = new Set(
203-
rushJson.projects
204-
.filter(p => p.shouldPublish && p.versionPolicyName)
205-
.map(p => p.versionPolicyName)
206-
);
207-
const filteredScopes = scopes.filter(s => publishablePolicies.has(s));
208-
console.log("publishable scopes", filteredScopes);
222+
console.log("commits", scopes);
209223

210-
core.setOutput('scopes', JSON.stringify(filteredScopes));
211-
core.setOutput('branch', branch);
224+
for (var i = 0; i < scopes.length; i++) {
225+
const scope = scopes[i];
226+
const comands = [
227+
'version',
228+
'--version-policy',
229+
scope,
230+
'--bump',
231+
]
232+
if (branchs.includes(branch)) {
233+
comands.push('--override-bump');
234+
comands.push('prerelease');
235+
comands.push('--override-prerelease-id');
236+
comands.push(branch);
237+
}
238+
console.log(comands);
239+
const data = await execa('rush', comands);
240+
console.log(data);
241+
}
212242
};

0 commit comments

Comments
 (0)