Skip to content

Commit

Permalink
Merge pull request #706 from rgoldberg/705-branch-in-version
Browse files Browse the repository at this point in the history
Include branch name in version name in certain conditions
  • Loading branch information
rgoldberg authored Jan 5, 2025
2 parents a5a928a + 75251ea commit 0d8d7c1
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
# Include all history & tags for script/version
fetch-depth: 0

- name: Setup repo
run: script/setup_workflow_repo

- name: Bootstrap
run: script/bootstrap

Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ jobs:
build-mode: manual
steps:
- name: Checkout repository
env:
GIT_CONFIG_COUNT: 1
GIT_CONFIG_KEY_0: init.defaultBranch
GIT_CONFIG_VALUE_0: ${{github.event.repository.default_branch}}
uses: actions/checkout@v4
with:
# Include all history & tags for script/version
fetch-depth: 0

- name: Setup repo
run: script/setup_workflow_repo

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/release-published.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ jobs:
GIT_CONFIG_KEY_0: init.defaultBranch
GIT_CONFIG_VALUE_0: ${{github.event.repository.default_branch}}
uses: actions/checkout@v4
with:
# Include all history & tags for script/version
fetch-depth: 0

- name: 🔧 Setup repo
run: script/setup_workflow_repo

- name: 🚰 Apply pr-pull label to custom tap formula bump PR
env:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/tag-pushed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ jobs:
GIT_CONFIG_KEY_0: init.defaultBranch
GIT_CONFIG_VALUE_0: ${{github.event.repository.default_branch}}
uses: actions/checkout@v4
with:
# Include all history & tags for script/version
fetch-depth: 0

- name: 🔧 Setup repo
run: script/setup_workflow_repo

- name: 🖋 Delete tag lacking valid signature
run: |
Expand Down
2 changes: 1 addition & 1 deletion script/lint
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ for source in Package.swift Sources Tests; do
done

printf -- $'--> 🐚 ShellCheck\n'
shellcheck -s bash -o all -e SC1088,SC1102,SC2296,SC2299,SC2300,SC2301,SC2312 -a -P SCRIPTDIR script/**/*(.)
shellcheck -s bash -o all -e SC1088,SC1102,SC2066,SC2296,SC2299,SC2300,SC2301,SC2312 -a -P SCRIPTDIR script/**/*(.)
((exit_code |= ${?}))

printf -- $'--> 〽️ Markdown\n'
Expand Down
13 changes: 13 additions & 0 deletions script/setup_workflow_repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/zsh -Ndefgku
#
# script/setup_workflow_repo
# mas
#
# Sets up the repo for use in a GitHub workflow.
#

. "${0:a:h}/_setup_script"

for branch in "${(f)"$(git for-each-ref refs/remotes/origin --format='%(if)%(symref)%(then)%(else)%(refname:strip=-1)%(end)')":#}"; do
git branch --track "${branch}" "origin/${branch}" >/dev/null 2>&1 || true
done
13 changes: 12 additions & 1 deletion script/version
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@

. "${0:a:h}/_setup_script"

printf $'%s%s\n'\
branch="${"$(git rev-parse --abbrev-ref HEAD)":/main}"

if [[ "${branch}" = HEAD ]]; then
if git merge-base --is-ancestor HEAD main; then
branch=
else
branch="${"${(@)"${(fnO)"$(git branch --format '%(ahead-behind:HEAD) %(refname:short)')"}"[1]}"##* }"
fi
fi

printf $'%s%s%s\n'\
"${branch:+"${branch}-"}"\
"${"$(git describe --tags 2>/dev/null)"#v}"\
"${"$(git diff-index HEAD --;git ls-files --exclude-standard --others)":+"${MAS_DIRTY_INDICATOR-+}"}"

0 comments on commit 0d8d7c1

Please sign in to comment.