2727 runs-on : ubuntu-latest
2828 # This job is required by the release job, so we should make it run both from Nushell repo and nightly repo
2929 # if: github.repository == 'nushell/nightly'
30+ # Map a step output to a job output
31+ outputs :
32+ skip : ${{ steps.vars.outputs.skip }}
33+ build_date : ${{ steps.vars.outputs.build_date }}
34+ nightly_tag : ${{ steps.vars.outputs.nightly_tag }}
3035 steps :
3136 - name : Checkout
3237 uses : actions/checkout@v4
@@ -59,16 +64,39 @@ jobs:
5964 # All the changes will be overwritten by the upstream main branch
6065 git reset --hard src/main
6166 git push origin main -f
67+
68+ - name : Create Tag and Output Tag Name
69+ if : github.repository == 'nushell/nightly'
70+ id : vars
71+ shell : nu {0}
72+ run : |
73+ let date = date now | format date %m%d
74+ let version = open Cargo.toml | get package.version
6275 let sha_short = (git rev-parse --short origin/main | str trim | str substring 0..6)
63- let tag_name = $'nightly-($sha_short)'
64- if (git ls-remote --tags origin $tag_name | is-empty) {
65- git tag -a $tag_name -m $'Nightly build from ($sha_short)'
76+ let latest_meta = http get https://api.github.com/repos/nushell/nightly/releases
77+ | sort-by -r created_at | get tag_name?.0? | default ''
78+ | parse '{version}-nightly.{build}+{hash}'
79+ if ($latest_meta.0?.hash? | default '') == $sha_short {
80+ print $'(ansi g)Latest nightly build is up-to-date, skip creating tag.(ansi reset)'
81+ $'skip=true(char nl)' o>> $env.GITHUB_OUTPUT
82+ exit 0
83+ }
84+ let prev_ver = $latest_meta.0?.version? | default '0.0.0'
85+ let build = if ($latest_meta | is-empty) or ($version != $prev_ver) { 1 } else {
86+ ($latest_meta | get build?.0? | default 0 | into int) + 1
87+ }
88+ let nightly_tag = $'($version)-nightly.($build)+($sha_short)'
89+ $'build_date=($date)(char nl)' o>> $env.GITHUB_OUTPUT
90+ $'nightly_tag=($nightly_tag)(char nl)' o>> $env.GITHUB_OUTPUT
91+ if (git ls-remote --tags origin $nightly_tag | is-empty) {
92+ git tag -a $nightly_tag -m $'Nightly build from ($sha_short)'
6693 git push origin --tags
6794 }
6895
6996 release :
7097 name : Nu
7198 needs : prepare
99+ if : needs.prepare.outputs.skip != 'true'
72100 strategy :
73101 fail-fast : false
74102 matrix :
@@ -121,9 +149,6 @@ jobs:
121149 os : ubuntu-22.04
122150
123151 runs-on : ${{matrix.os}}
124- # Map a step output to a job output
125- outputs :
126- sha_short : ${{ steps.vars.outputs.sha_short }}
127152 steps :
128153 - uses : actions/checkout@v4
129154 with :
@@ -164,13 +189,6 @@ jobs:
164189 search_existing : open
165190 filename : .github/AUTO_ISSUE_TEMPLATE/nightly-build-fail.md
166191
167- - name : Set Outputs of Short SHA
168- id : vars
169- run : |
170- echo "date=$(date -u +'%Y-%m-%d')" >> $GITHUB_OUTPUT
171- sha_short=$(git rev-parse --short HEAD)
172- echo "sha_short=${sha_short:0:7}" >> $GITHUB_OUTPUT
173-
174192 # REF: https://github.com/marketplace/actions/gh-release
175193 # Create a release only in nushell/nightly repo
176194 - name : Publish Archive
@@ -179,13 +197,13 @@ jobs:
179197 with :
180198 prerelease : true
181199 files : ${{ steps.nu.outputs.archive }}
182- tag_name : nightly- ${{ steps.vars .outputs.sha_short }}
183- name : Nu-nightly- ${{ steps.vars .outputs.date }}-${{ steps.vars .outputs.sha_short }}
200+ tag_name : ${{ needs.prepare .outputs.nightly_tag }}
201+ name : ${{ needs.prepare .outputs.build_date }}-${{ needs.prepare .outputs.nightly_tag }}
184202 env :
185203 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
186204
187205 sha256sum :
188- needs : release
206+ needs : [prepare, release]
189207 name : Create Sha256sum
190208 runs-on : ubuntu-latest
191209 if : github.repository == 'nushell/nightly'
@@ -194,7 +212,7 @@ jobs:
194212 env :
195213 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
196214 run : >-
197- gh release download nightly- ${{ needs.release .outputs.sha_short }}
215+ gh release download ${{ needs.prepare .outputs.nightly_tag }}
198216 --repo ${{ github.repository }}
199217 --pattern '*'
200218 --dir release
@@ -206,7 +224,7 @@ jobs:
206224 draft : false
207225 prerelease : true
208226 files : SHA256SUMS
209- tag_name : nightly- ${{ needs.release .outputs.sha_short }}
227+ tag_name : ${{ needs.prepare .outputs.nightly_tag }}
210228 env :
211229 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
212230
0 commit comments