Skip to content

Commit 1962d8b

Browse files
Set correct number for the rc metadata
Closes #33
1 parent 47bdcc7 commit 1962d8b

4 files changed

Lines changed: 58 additions & 6 deletions

File tree

.github/workflows/test-release.yaml

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,48 @@ jobs:
1919
with:
2020
# all history is needed to crawl it properly
2121
fetch-depth: 0
22+
- name: Count run number
23+
id: count
24+
uses: actions/github-script@v9
25+
with:
26+
script: |
27+
const pr = context.payload.pull_request;
28+
if (!pr) {
29+
core.setFailed("This workflow must be triggered by a pull request.");
30+
return;
31+
}
32+
33+
const pr_number = pr.number;
34+
const workflow_name = context.workflow;
35+
const branch_name = pr.head.ref;
36+
const event_match = "pull_request";
37+
console.log("PR Number: " + pr_number);
38+
console.log("Workflow name: " + workflow_name);
39+
console.log("Branch name: " + branch_name);
40+
41+
if (!pr_number) {
42+
console.log("No pull request number found in context.");
43+
core.setOutput("count", 0);
44+
return;
45+
}
46+
47+
const runs = await github.rest.actions.listWorkflowRunsForRepo({
48+
owner: context.repo.owner,
49+
repo: context.repo.repo,
50+
event: event_match,
51+
branch: branch_name,
52+
per_page: 100
53+
});
54+
55+
const filtered = runs.data.workflow_runs.filter(run =>
56+
run.name === workflow_name &&
57+
run.event === event_match &&
58+
run.pull_requests?.some(p => p.number === pr_number)
59+
);
60+
console.log("Matches for filters aka runs: " + filtered.length);
61+
62+
const count = filtered.length > 0 ? filtered.length : 1;
63+
core.setOutput("rc_number", count);
2264
- name: Set up Python
2365
uses: actions/setup-python@v6
2466
with:
@@ -54,7 +96,7 @@ jobs:
5496
--changelog_file changelog.md \
5597
--version_file be_upy_blink/version.py \
5698
--version_file_type py \
57-
--additional_version_info="-rc${{ github.run_number }}.dev${{ github.event.number }}" \
99+
--additional_version_info="-rc${{ steps.count.outputs.rc_number }}.dev${{ github.event.number }}" \
58100
--debug
59101
- name: Build package
60102
run: |
@@ -70,7 +112,7 @@ jobs:
70112
# https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
71113
# ${{ github.repository }} and ${{ github.ref_name }} can't be used
72114
# for artifact name due to unallowed '/'
73-
name: dist_repo.${{ github.event.repository.name }}_sha.${{ github.sha }}_build.${{ github.run_number }}
115+
name: dist_repo.${{ github.event.repository.name }}_sha.${{ github.sha }}_build.${{ steps.count.outputs.rc_number }}
74116
path: dist/*.tar.gz
75117
retention-days: 14
76118
- name: Publish package
@@ -89,8 +131,8 @@ jobs:
89131
# or you set the "contents" permissions to "write" as in this example
90132
changelog-path: changelog.md
91133
tag-name-prefix: ''
92-
tag-name-extension: '-rc${{ github.run_number }}.dev${{ github.event.number }}'
134+
tag-name-extension: '-rc${{ steps.count.outputs.rc_number }}.dev${{ github.event.number }}'
93135
release-name-prefix: ''
94-
release-name-extension: '-rc${{ github.run_number }}.dev${{ github.event.number }}'
136+
release-name-extension: '-rc${{ steps.count.outputs.rc_number }}.dev${{ github.event.number }}'
95137
draft-release: true
96138
prerelease: true

.snippets/33.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## Set correct release candidate number
2+
<!--
3+
type: bugfix
4+
scope: all
5+
affected: all
6+
-->
7+
8+
This change creates the correct release candidate number based on the action run of a pull request workflow run `test-release` instead of the total number of this workflow run. By this fix, the `-rcX` metadata starts at `1` and is incremented with every push, no matter if the push is a force push or a classic new commit on top in a ongoing pull request.
9+
10+
This closes [#33](https://github.com/brainelectronics/micropython-package-template/issues/33)

be_upy_blink/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
22
# -*- coding: UTF-8 -*-
33

4-
__version_info__ = ("0", "13", "0")
4+
__version_info__ = ("0", "13", "1")
55
__version__ = '.'.join(__version_info__)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
]
1515
],
1616
"deps": [],
17-
"version": "0.13.0"
17+
"version": "0.13.1"
1818
}

0 commit comments

Comments
 (0)