|
19 | 19 | with: |
20 | 20 | # all history is needed to crawl it properly |
21 | 21 | 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); |
22 | 64 | - name: Set up Python |
23 | 65 | uses: actions/setup-python@v6 |
24 | 66 | with: |
|
54 | 96 | --changelog_file changelog.md \ |
55 | 97 | --version_file be_upy_blink/version.py \ |
56 | 98 | --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 }}" \ |
58 | 100 | --debug |
59 | 101 | - name: Build package |
60 | 102 | run: | |
|
70 | 112 | # https://docs.github.com/en/actions/learn-github-actions/contexts#github-context |
71 | 113 | # ${{ github.repository }} and ${{ github.ref_name }} can't be used |
72 | 114 | # 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 }} |
74 | 116 | path: dist/*.tar.gz |
75 | 117 | retention-days: 14 |
76 | 118 | - name: Publish package |
|
89 | 131 | # or you set the "contents" permissions to "write" as in this example |
90 | 132 | changelog-path: changelog.md |
91 | 133 | 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 }}' |
93 | 135 | 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 }}' |
95 | 137 | draft-release: true |
96 | 138 | prerelease: true |
0 commit comments