Skip to content

Commit

Permalink
feat: Rename nightly release tag in semver format
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcer committed Jan 11, 2025
1 parent c585567 commit 0000000
Showing 1 changed file with 36 additions and 18 deletions.
54 changes: 36 additions & 18 deletions .github/workflows/nightly-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ jobs:
runs-on: ubuntu-latest
# This job is required by the release job, so we should make it run both from Nushell repo and nightly repo
# if: github.repository == 'nushell/nightly'
# Map a step output to a job output
outputs:
skip: ${{ steps.vars.outputs.skip }}
build_date: ${{ steps.vars.outputs.build_date }}
nightly_tag: ${{ steps.vars.outputs.nightly_tag }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -59,16 +64,39 @@ jobs:
# All the changes will be overwritten by the upstream main branch
git reset --hard src/main
git push origin main -f
- name: Create Tag and Output Tag Name
if: github.repository == 'nushell/nightly'
id: vars
shell: nu {0}
run: |
let date = date now | format date %m%d
let version = open Cargo.toml | get package.version
let sha_short = (git rev-parse --short origin/main | str trim | str substring 0..6)
let tag_name = $'nightly-($sha_short)'
if (git ls-remote --tags origin $tag_name | is-empty) {
git tag -a $tag_name -m $'Nightly build from ($sha_short)'
let latest_meta = http get https://api.github.com/repos/nushell/nightly/releases
| sort-by -r created_at | get tag_name?.0? | default ''
| parse '{version}-nightly.{build}+{hash}'
if ($latest_meta.0?.hash? | default '') == $sha_short {
print $'(ansi g)Latest nightly build is up-to-date, skip creating tag.(ansi reset)'
$'skip=true(char nl)' o>> $env.GITHUB_OUTPUT
exit 0
}
let prev_ver = $latest_meta.0?.version? | default '0.0.0'
let build = if ($latest_meta | is-empty) or ($version != $prev_ver) { 1 } else {
($latest_meta | get build?.0? | default 0 | into int) + 1
}
let nightly_tag = $'($version)-nightly.($build)+($sha_short)'
$'build_date=($date)(char nl)' o>> $env.GITHUB_OUTPUT
$'nightly_tag=($nightly_tag)(char nl)' o>> $env.GITHUB_OUTPUT
if (git ls-remote --tags origin $nightly_tag | is-empty) {
git tag -a $nightly_tag -m $'Nightly build from ($sha_short)'
git push origin --tags
}
release:
name: Nu
needs: prepare
if: needs.prepare.outputs.skip != 'true'
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -121,9 +149,6 @@ jobs:
os: ubuntu-22.04

runs-on: ${{matrix.os}}
# Map a step output to a job output
outputs:
sha_short: ${{ steps.vars.outputs.sha_short }}
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -164,13 +189,6 @@ jobs:
search_existing: open
filename: .github/AUTO_ISSUE_TEMPLATE/nightly-build-fail.md

- name: Set Outputs of Short SHA
id: vars
run: |
echo "date=$(date -u +'%Y-%m-%d')" >> $GITHUB_OUTPUT
sha_short=$(git rev-parse --short HEAD)
echo "sha_short=${sha_short:0:7}" >> $GITHUB_OUTPUT
# REF: https://github.com/marketplace/actions/gh-release
# Create a release only in nushell/nightly repo
- name: Publish Archive
Expand All @@ -179,13 +197,13 @@ jobs:
with:
prerelease: true
files: ${{ steps.nu.outputs.archive }}
tag_name: nightly-${{ steps.vars.outputs.sha_short }}
name: Nu-nightly-${{ steps.vars.outputs.date }}-${{ steps.vars.outputs.sha_short }}
tag_name: ${{ needs.prepare.outputs.nightly_tag }}
name: ${{ needs.prepare.outputs.build_date }}-${{ needs.prepare.outputs.nightly_tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

sha256sum:
needs: release
needs: [prepare, release]
name: Create Sha256sum
runs-on: ubuntu-latest
if: github.repository == 'nushell/nightly'
Expand All @@ -194,7 +212,7 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: >-
gh release download nightly-${{ needs.release.outputs.sha_short }}
gh release download ${{ needs.prepare.outputs.nightly_tag }}
--repo ${{ github.repository }}
--pattern '*'
--dir release
Expand All @@ -206,7 +224,7 @@ jobs:
draft: false
prerelease: true
files: SHA256SUMS
tag_name: nightly-${{ needs.release.outputs.sha_short }}
tag_name: ${{ needs.prepare.outputs.nightly_tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down

0 comments on commit 0000000

Please sign in to comment.