diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000..024c88f --- /dev/null +++ b/.github/workflows/push.yml @@ -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 \ No newline at end of file diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..7345cc6 --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,16 @@ +{ + "branches": [ + "main" + ], + "plugins": [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + [ + "@semantic-release/github", + { + "successComment": false, + "releasedLabels": false + } + ] + ] +} \ No newline at end of file diff --git a/npm-bump b/npm-bump index f1c569e..535be15 100755 --- a/npm-bump +++ b/npm-bump @@ -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]}( |$)" @@ -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() { @@ -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 @@ -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 } @@ -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 } diff --git a/tests/packages_not_already_updated.sh b/tests/packages_not_already_updated.sh index 8c0378c..2922001 100644 --- a/tests/packages_not_already_updated.sh +++ b/tests/packages_not_already_updated.sh @@ -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() { @@ -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 lodash@4.17.19 &> /dev/null; } 2>&1 diff --git a/tests/packages_not_already_updated_markdown.sh b/tests/packages_not_already_updated_markdown.sh index 61d939b..8dc279e 100644 --- a/tests/packages_not_already_updated_markdown.sh +++ b/tests/packages_not_already_updated_markdown.sh @@ -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() { @@ -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 lodash@4.17.19 &> /dev/null; } 2>&1 diff --git a/tests/runner.sh b/tests/runner.sh index 57100d8..ad2be04 100644 --- a/tests/runner.sh +++ b/tests/runner.sh @@ -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