44# See also:
55# https://github.com/actions/upload-artifact
66# https://docs.github.com/en/actions/reference/workflows-and-actions/variables
7+ # https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax
78name : " GHA-01: Make dist and docs tarballs, see workflow page for links"
89
910on :
1314 - v*
1415 pull_request_target :
1516 # The branches below must be a subset of the branches above
17+ # Note that for PRs this runs the copy of workflow in the
18+ # target branch (and only then gets some of the permissions
19+ # listed below), and identification/naming of PR source vs.
20+ # a pushed branch (e.g. master updated by a PR merge) is
21+ # tricky.
1622 branches : [ "master", "FTY", "fightwarn", "FTY-obs" ]
1723 schedule :
1824 - cron : ' 15 12 * * 0'
1925 workflow_dispatch :
2026 # Allow manually running the action, e.g. if disabled after some quietness in the source
2127
2228permissions :
23- contents : read
29+ contents : write
2430 issues : write
2531 pull-requests : write
2632
@@ -29,43 +35,24 @@ jobs:
2935 name : Make Dist and Docs Tarballs
3036 # FIXME: Prepare/maintain a container image with pre-installed
3137 # NUT build/tooling prereqs (save about 3 minutes per run!)
38+ # Maybe https://aschmelyun.com/blog/using-docker-run-inside-of-github-actions/
39+ # => https://github.com/addnab/docker-run-action can help
3240 runs-on : ubuntu-latest
33- # permissions:
34- # #actions: read
35- # actions: write
36- # #contents: read
37- # contents: write
38- # repository-projects: write
39- # security-events: write
40- # pull-requests: write
41- # issues: write
4241
4342 strategy :
4443 fail-fast : false
4544
4645 steps :
4746 # Post early so this would be about the top comment in the PR trail
4847 # (easy to see, contents replaced later)
49-
50- # - name: "GHA-01: Make dist and docs tarballs - report download URL - t1"
51- # uses: thollander/actions-comment-pull-request@v3
52- # # if: startsWith(github.ref, 'refs/pull/')
53- # continue-on-error: true
54- # with:
55- # comment-tag: latest-tarball
56- # message: Sticky note -- Dist and Docs tarballs will be linked here after the "make dist" job completes.
57- # #github-token: ${{ secrets.MAKE_DIST_TOKEN }}
58-
59- - name : " GHA-01: Make dist and docs tarballs - report download URL - s1"
48+ - name : " GHA-01: Make dist and docs tarballs - report download URL (placeholder) as a first-ever PR comment"
6049 uses : marocchino/sticky-pull-request-comment@v2
61- if : startsWith(github.ref, 'refs/pull/')
50+ if : startsWith(github.ref, 'refs/pull/') || github.event.pull_request.number > 0
6251 continue-on-error : true
6352 with :
6453 header : latest-tarball-sticky
6554 only_create : true
6655 message : Sticky note -- Dist and Docs tarballs will be linked here after the "make dist" job completes.
67- # github-token: ${{ secrets.MAKE_DIST_TOKEN }}
68- # GITHUB_TOKEN: ${{ secrets.MAKE_DIST_TOKEN }}
6956
7057 - name : Checkout repository
7158 uses : actions/checkout@v5
@@ -74,18 +61,25 @@ jobs:
7461 fetch-tags : true
7562
7663 # https://github.com/marketplace/actions/substitute-string
77- # https://docs.github.com/en/actions/reference/workflows-and-actions/variables
78- # https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax
64+ # See also examples in https://github.com/dhimmel/dump-actions-context/
7965 # Note it warns about "unexpected input(s)" with replacement tokens below,
8066 # as they are by design not predefined, as far as actions API is concened.
8167 # They still work for substitutions though.
8268 - uses : bluwy/substitute-string-action@v3
8369 id : subst-github-ref-name
8470 with :
85- _input-text : " ${{ github.head_ref || github.ref_name }}"
71+ _input-text : " ${{ github.event.pull_request.number > 0 && format('PR-{0}', github.event.pull_request.number) || github. head_ref || github.ref_name }}"
8672 " " : _
8773 " / " : _
88- - run : echo "${{ steps.subst-github-ref-name.outputs.result }}"
74+
75+ - name : Debug PR/branch identification
76+ run : |
77+ echo "steps.subst-github-ref-name.outputs.result='${{ steps.subst-github-ref-name.outputs.result }}'" || true
78+ echo "github.event.pull_request.number='${{ github.event.pull_request.number }}'" || true
79+ echo "format('PR-{0}', github.event.pull_request.number)='${{ format('PR-{0}', github.event.pull_request.number) }}'" || true
80+ echo "github.head_ref='${{ github.head_ref }}'" || true
81+ echo "github.ref='${{ github.ref }}'" || true
82+ echo "github.ref_name='${{ github.ref_name }}'" || true
8983
9084 # Make build identification more useful (so we use no fallbacks in script)
9185 - name : Try to get more Git metadata
@@ -261,7 +255,6 @@ jobs:
261255 artifact_id: id,
262256 })
263257 })
264- # github-token: ${{ secrets.MAKE_DIST_TOKEN }}
265258
266259 - name : Upload tarball and its checksum artifacts
267260 uses : actions/upload-artifact@v4
@@ -273,33 +266,20 @@ jobs:
273266 compression-level : 0
274267 overwrite : true
275268
276- # https://github.com/thollander/actions-comment-pull-request
277269 # FIXME: Something that adds/updates Github Checks would be better
278270 # as it would be seen in the list attached to a status icon of any
279271 # build (e.g. history of master branch)
280-
281- # - name: "GHA-01: Make dist and docs tarballs - report download URL - t2"
282- # uses: thollander/actions-comment-pull-request@v3
283- # # if: startsWith(github.ref, 'refs/pull/')
284- # continue-on-error: true
285- # with:
286- # comment-tag: latest-tarball
287- # message: Dist and Docs [NUT-tarballs-${{ steps.subst-github-ref-name.outputs.result }}.zip](${{ steps.upload_artifact.outputs.artifact-url }}) are available for commit ${{ github.event.pull_request.head.sha || github.sha }}
288- # #github-token: ${{ secrets.MAKE_DIST_TOKEN }}
289-
290272 # https://github.com/marocchino/sticky-pull-request-comment
291- - name : " GHA-01: Make dist and docs tarballs - report download URL - s2 "
273+ - name : " GHA-01: Make dist and docs tarballs - report download URL as a PR comment "
292274 uses : marocchino/sticky-pull-request-comment@v2
293- if : startsWith(github.ref, 'refs/pull/')
275+ if : startsWith(github.ref, 'refs/pull/') || github.event.pull_request.number > 0
294276 continue-on-error : true
295277 with :
296278 header : latest-tarball-sticky
297279 message : Dist and Docs [NUT-tarballs-${{ steps.subst-github-ref-name.outputs.result }}.zip](${{ steps.upload_artifact.outputs.artifact-url }}) are available for commit ${{ github.event.pull_request.head.sha || github.sha }}
298- # github-token: ${{ secrets.MAKE_DIST_TOKEN }}
299- # GITHUB_TOKEN: ${{ secrets.MAKE_DIST_TOKEN }}
300280
301281 # https://github.com/marketplace/actions/commit-comment
302- - name : " GHA-01: Make dist and docs tarballs - report download URL - commit comment"
282+ - name : " GHA-01: Make dist and docs tarballs - report download URL as a commit comment"
303283 uses : peter-evans/commit-comment@v4
304284 continue-on-error : true
305285 with :
0 commit comments