githubactions's People
githubactions's Issues
Be explicit with brace expansion within a mixed string
This is another personal thing that I think lends clarity.
When creating a string that contains both literal and interpolated/expanded values, use bash's more explicit variable notation:
SNAPSHOT_BRANCH="release${RELEASE_NUM}-SNAPSHOT"
shellcheck/yamllint sanity
I try to run a tool called shellcheck
over all my shell scripts.
It'll help you catch a bunch of stuff and generally offers good explanation of why you'd prefer its corrections.
https://github.com/koalaman/shellcheck
Another small sanity checker I use for packard
is yamllint
:
https://github.com/adrienverge/yamllint
Mixed if form
This might be a personal thing, but for clarity, I find its easier to stick to either &&
, ||
OR if .. then
statements.
So the above example could be re-written as just:
if echo $GITHUB_REF | grep 'refs/heads'; then
...
if/then test for a command's existence
Can be written more simply as:
if command -v hub; then
...
Since command
will exit with an status/return greater than 0 if there's no matching command on $PATH
RC of "echo" being tested
gitHubActions/branch-release/branch_release.sh
Lines 55 to 59 in 55b8366
Since the $?
special variable follows the echo
command (which will always exit w/ 0
), this if statement will always be true.
There's a bash
shell option to help with this kind of logic, set -o pipefail
, which causes a command to fail if any constituent command fails.
Read more here: http://redsymbol.net/articles/unofficial-bash-strict-mode
Double quote variable values/shell expansion
shellcheck will also yell at you for this, but I personally find it helps clarify where this type of expansion is happening.
This can be written as:
TAG="$(echo "$GITHUB_REF" | sed -e 's/refs\/tags\///')"
Bashisms
Double square brackets, are for string comparison and only apply in bash.
In pure sh
, you only need [ -z "$VAR" ]
to test for an empty/unset variable.
Reference bash in shebag
Since bash is being installed, you'll want to make sure its being used for any scripts by specifying a more explicit shebag.
#!/usr/bin/env bash
should do the trick.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.