Skip to content

Commit

Permalink
Merge pull request #6 from VincentHardouin/fix-shellcheck-error
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentHardouin authored Feb 21, 2022
2 parents dfd669c + d3087f2 commit df34525
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 22 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Push

on: push

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
name: Shellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master

commitlint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Lint Commit
uses: wagoid/commitlint-github-action@v3

release:
name: Publish new release
needs: [lint, commitlint]
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 14
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx semantic-release
16 changes: 16 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"branches": [
"main"
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/github",
{
"successComment": false,
"releasedLabels": false
}
]
]
}
27 changes: 15 additions & 12 deletions npm-bump
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function transform_exclude_package_names() {
join="";
for index in "${!array[@]}"
do
if [ $index -eq 0 ]; then
if [ "$index" -eq 0 ]; then
join="(^| )${array[index]}( |$)"
else
join="${join}|(^| )${array[index]}( |$)"
Expand Down Expand Up @@ -64,9 +64,9 @@ function undo_changes() {
}

function add_updated_package_informations() {
updated_packages+=($1)
old_version_packages+=($2)
new_version_packages+=($3)
updated_packages+=("$1")
old_version_packages+=("$2")
new_version_packages+=("$3")
}

function bump_version() {
Expand All @@ -77,20 +77,22 @@ function bump_version() {
fi

if [ -n "$outdated_packages" ]; then
while read package actual_version coll3 latest_version col5; do
# shellcheck disable=SC2034
while read -r package actual_version coll3 latest_version col4; do
echo "Try to bump ${package} from ${actual_version} to ${latest_version}"

if [ -z ${no_test} ]; then
npm install $package@$latest_version && npm test
npm install "$package"@"$latest_version" && npm test
else
npm install $package@$latest_version
npm install "$package"@"$latest_version"
fi

# shellcheck disable=SC2181
if [ $? -eq 0 ]; then
commit_bump $package $actual_version $latest_version
add_updated_package_informations $package $actual_version $latest_version
commit_bump "$package" "$actual_version" "$latest_version"
add_updated_package_informations "$package" "$actual_version" "$latest_version"
else
no_updated_packages+=(${package})
no_updated_packages+=("${package}")
undo_changes
fi

Expand All @@ -104,7 +106,7 @@ function show_updated_packages() {
printf "%.0s-" {1..38}
printf "\n"
for index in ${!updated_packages[*]}; do
printf "%-15s %9s %9s\n" ${updated_packages[$index]} ${old_version_packages[$index]} ${new_version_packages[$index]}
printf "%-15s %9s %9s\n" "${updated_packages[$index]}" "${old_version_packages[$index]}" "${new_version_packages[$index]}"
done
}

Expand All @@ -120,8 +122,9 @@ function show_updated_packages_in_markdown() {
function show_no_updated_package() {
if [ ${#no_updated_packages[@]} -gt 0 ]; then
printf "\n%s\n" "Packages not updated :"
# shellcheck disable=SC2048
for package in ${no_updated_packages[*]}; do
printf "%s %s\n" "-" $package
printf "%s %s\n" "-" "$package"
done
fi
}
Expand Down
8 changes: 4 additions & 4 deletions tests/packages_not_already_updated.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ function stub_npm_test() {
replacement_text='"test": "exit 0"'
file="$PWD/package.json"
test_line=8
sed -i.bak "${test_line}s/.*/${replacement_text}/" $file && rm $file.bak
sed -i.bak "${test_line}s/.*/${replacement_text}/" "$file" && rm "$file".bak
}

function restore_npm_test() {
replacement_text=' "test": "exit 1"'
file="$PWD/package.json"
test_line=8
sed -i.bak "${test_line}s/.*/${replacement_text}/" $file && rm $file.bak
sed -i.bak "${test_line}s/.*/${replacement_text}/" "$file" && rm "$file".bak
}

function remove_created_commit() {
Expand All @@ -24,8 +24,8 @@ current_dir=$PWD
directory_under_test='./npm-directory'
expected_output="Package Old New
--------------------------------------
lodash 4.17.19 4.17.20"
expected_commit_message="Bump lodash from 4.17.19 to 4.17.20"
lodash 4.17.19 4.17.21"
expected_commit_message="Bump lodash from 4.17.19 to 4.17.21"

cd $directory_under_test || exit
{ npm install --quiet [email protected] &> /dev/null; } 2>&1
Expand Down
8 changes: 4 additions & 4 deletions tests/packages_not_already_updated_markdown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ function stub_npm_test() {
replacement_text='"test": "exit 0"'
file="$PWD/package.json"
test_line=8
sed -i.bak "${test_line}s/.*/${replacement_text}/" $file && rm $file.bak
sed -i.bak "${test_line}s/.*/${replacement_text}/" "$file" && rm "$file".bak
}

function restore_npm_test() {
replacement_text=' "test": "exit 1"'
file="$PWD/package.json"
test_line=8
sed -i.bak "${test_line}s/.*/${replacement_text}/" $file && rm $file.bak
sed -i.bak "${test_line}s/.*/${replacement_text}/" "$file" && rm "$file".bak
}

function remove_created_commit() {
Expand All @@ -24,8 +24,8 @@ current_dir=$PWD
directory_under_test='./npm-directory'
expected_output="Package|Old|New
-|-|-
lodash|4.17.19|4.17.20"
expected_commit_message="Bump lodash from 4.17.19 to 4.17.20"
lodash|4.17.19|4.17.21"
expected_commit_message="Bump lodash from 4.17.19 to 4.17.21"

cd $directory_under_test || exit
{ npm install --quiet [email protected] &> /dev/null; } 2>&1
Expand Down
4 changes: 2 additions & 2 deletions tests/runner.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

while IFS= read -r -d '' file; do
find ./* -maxdepth 0 -type f -name "*.sh" -not -path "./runner.sh" -print0 | while IFS= read -r -d '' file; do
bash "$file" || echo "$file" exit 1
done < <(find ./* -maxdepth 0 -type f -name "*.sh" -not -path "./runner.sh" -print0)
done

0 comments on commit df34525

Please sign in to comment.