Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
unison/scripts/check-version.bash at trunk · JavaDerek/unison · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
JavaDerek
unison
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
trunk
Breadcrumbs
unison
/
scripts
/
check-version.bash
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
58 lines (53 loc) · 2.25 KB
trunk
Breadcrumbs
unison
/
scripts
/
check-version.bash
Copy path
Top
File metadata and controls
Code
Blame
58 lines (53 loc) · 2.25 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
SCRIPTNAME=
"
$(
readlink -f --
"
${BASH_SOURCE[0]}
"
)
"
SCRIPTDIR=
"
$(
dirname --
"
$SCRIPTNAME
"
)
"
#
shellcheck disable=SC2120
#
because the argument is optional
function
indent()
{
local
indentSize=2
local
indent=
${1
:-
1}
pr -to
$((
indent
*
indentSize
))
}
function
_version_check_failed()
{
local
fallback_exit_code=
"
$1
"
shift
if
declare
-F prereq_failed
>
/dev/null
;
then
prereq_failed
"
$@
"
else
>&2
printf
'
%s\n
'
"
$@
"
exit
"
$fallback_exit_code
"
fi
}
#
# This function checks
#
# 1. that the command is on PATH,
#
# 2. that the version of the command found matches our expectation (command must support `--version`), and
#
# 3. if the user has Nix, that our expectation matches the version specified by our Nix config.
#
#
#
# Failing either of the first two checks causes an error, while the third is only a warning (because the third
#
# indicates a code issue, not a user issue).
function
version-equals
{
local
command=
"
$1
"
#
# This would ideally be read from ./nix/versions.nix, but we can’t assume the user has Nix, so we hardcode this,
#
# then at the end of the script, if the user _does_ have Nix, we check if this hardcoded version is the one we
#
# want.
local
expected_version=
"
$2
"
if
command
-v
"
$command
"
>
/dev/null
;
then
if
!
"
$command
"
--version
|
grep -q
"
${expected_version}
"
;
then
_version_check_failed \
78 \
"
Skipping
$command
check – found, but the version isn’t
${expected_version}
:
"
\
"
$(
"
$command
"
--version
|
indent
)
"
fi
else
_version_check_failed 127
"
Skipping
$command
check – not found on PATH
"
fi
#
# When the user has Nix, check that `expected_version` matches what we require for Nix.
if
command
-v nix
>
/dev/null
;
then
nix_reported_version=
"
$(
nix
eval
--file
$SCRIPTDIR
/../nix/versions.nix
"
$command
"
--raw
)
"
if
[[
"
$expected_version
"
!=
"
$nix_reported_version
"
]]
;
then
>&2
echo
"
⚠️ Running
$command
check with unexpected version.
"
>&2
echo
"
Please update ‘version-equals
${command}
\"
$expected_version
\"
’ called from
"
>&2
echo
"
$SCRIPTNAME
"
>&2
echo
"
to use
\"
$nix_reported_version
\"
and open a PR.
"
fi
fi
}
You can’t perform that action at this time.