Skip to content

Commit

Permalink
Switch to new μpkg package format
Browse files Browse the repository at this point in the history
  • Loading branch information
andsens committed May 21, 2024
1 parent c1547f4 commit aa9b27a
Show file tree
Hide file tree
Showing 20 changed files with 111 additions and 80 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Release

on:
push:
tags: ['v*']

jobs:
test:
uses: ./.github/workflows/test.yaml
secrets: inherit
release:
needs: [test]
permissions:
contents: write
runs-on: ubuntu-latest
name: Create GitHub release
steps:
- uses: orbit-online/upkg-release@v1
14 changes: 6 additions & 8 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ name: Test

on:
push:
branches: [ '*' ]
tags: [ 'v*' ]
branches: ['*']
tags: ['!v*']
workflow_call: {}

jobs:
lint:
Expand All @@ -18,13 +19,10 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Setup BATS
run: |
git clone --depth 1 --branch v1.10.0 https://github.com/bats-core/bats-core.git /tmp/bats
sudo /tmp/bats/install.sh /usr/local
rm -rf /tmp/bats
- name: Install bats
uses: bats-core/[email protected]
- name: Checkout
uses: actions/checkout@v4
- uses: orbit-online/upkg@v0.14.0
- uses: orbit-online/upkg-install@v1
- name: Run tests
run: bats .
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Orbit Online A/S

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ Bash tools to modify `$PATH`.

## Installation

With [μpkg](https://github.com/orbit-online/upkg)

```
upkg install -g orbit-online/path-tools@<VERSION>
```
See [the latest release](https://github.com/orbit-online/path-tools/releases/latest) for instructions.

## Behavior

Expand Down
5 changes: 5 additions & 0 deletions bin/path_append
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
# shellcheck source-path=..
set -eo pipefail; shopt -s inherit_errexit
source "$(realpath "$(dirname "$(realpath "${BASH_SOURCE[0]}")")/..")/path-tools.sh"
path_append "$@"
5 changes: 5 additions & 0 deletions bin/path_contains
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
# shellcheck source-path=..
set -eo pipefail; shopt -s inherit_errexit
source "$(realpath "$(dirname "$(realpath "${BASH_SOURCE[0]}")")/..")/path-tools.sh"
path_contains "$@"
5 changes: 5 additions & 0 deletions bin/path_insert_after
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
# shellcheck source-path=..
set -eo pipefail; shopt -s inherit_errexit
source "$(realpath "$(dirname "$(realpath "${BASH_SOURCE[0]}")")/..")/path-tools.sh"
path_insert_after "$@"
5 changes: 5 additions & 0 deletions bin/path_insert_before
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
# shellcheck source-path=..
set -eo pipefail; shopt -s inherit_errexit
source "$(realpath "$(dirname "$(realpath "${BASH_SOURCE[0]}")")/..")/path-tools.sh"
path_insert_before "$@"
5 changes: 5 additions & 0 deletions bin/path_prepend
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
# shellcheck source-path=..
set -eo pipefail; shopt -s inherit_errexit
source "$(realpath "$(dirname "$(realpath "${BASH_SOURCE[0]}")")/..")/path-tools.sh"
path_prepend "$@"
5 changes: 5 additions & 0 deletions bin/path_remove
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
# shellcheck source-path=..
set -eo pipefail; shopt -s inherit_errexit
source "$(realpath "$(dirname "$(realpath "${BASH_SOURCE[0]}")")/..")/path-tools.sh"
path_remove "$@"
5 changes: 5 additions & 0 deletions bin/path_validate
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
# shellcheck source-path=..
set -eo pipefail; shopt -s inherit_errexit
source "$(realpath "$(dirname "$(realpath "${BASH_SOURCE[0]}")")/..")/path-tools.sh"
path_validate "$@"
4 changes: 0 additions & 4 deletions path_append.sh

This file was deleted.

4 changes: 0 additions & 4 deletions path_contains.sh

This file was deleted.

4 changes: 0 additions & 4 deletions path_insert_after.sh

This file was deleted.

4 changes: 0 additions & 4 deletions path_insert_before.sh

This file was deleted.

4 changes: 0 additions & 4 deletions path_prepend.sh

This file was deleted.

4 changes: 0 additions & 4 deletions path_remove.sh

This file was deleted.

4 changes: 0 additions & 4 deletions path_validate.sh

This file was deleted.

58 changes: 29 additions & 29 deletions test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,92 +3,92 @@

setup_file() {
bats_require_minimum_version 1.5.0
export PATH=$BATS_TEST_DIRNAME:$HOME/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export PATH=$BATS_TEST_DIRNAME/bin:$HOME/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
}

@test 'path_append appends' {
run path_append.sh TEST
run path_append TEST
[ "$output" = "$PATH:TEST" ]
}

@test 'path_prepend prepends' {
run path_prepend.sh TEST
run path_prepend TEST
[ "$output" = "TEST:$PATH" ]
}

@test 'path_insert_after with match inserts after match' {
run path_insert_after.sh TEST /usr/bin
[ "$output" = "$BATS_TEST_DIRNAME:$HOME/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:TEST:/sbin:/bin" ]
run path_insert_after TEST /usr/bin
[ "$output" = "$BATS_TEST_DIRNAME/bin:$HOME/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:TEST:/sbin:/bin" ]
}

@test 'path_insert_after without match appends' {
run path_insert_after.sh TEST UNMATCHED
[ "$output" = "$BATS_TEST_DIRNAME:$HOME/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:TEST" ]
run path_insert_after TEST UNMATCHED
[ "$output" = "$BATS_TEST_DIRNAME/bin:$HOME/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:TEST" ]
}

@test 'path_insert_after with glob match inserts after last match' {
run path_insert_after.sh TEST '*/?(.)local/*'
[ "$output" = "$BATS_TEST_DIRNAME:$HOME/.local/bin:/usr/local/sbin:/usr/local/bin:TEST:/usr/sbin:/usr/bin:/sbin:/bin" ]
run path_insert_after TEST '*/?(.)local/*'
[ "$output" = "$BATS_TEST_DIRNAME/bin:$HOME/.local/bin:/usr/local/sbin:/usr/local/bin:TEST:/usr/sbin:/usr/bin:/sbin:/bin" ]
}

@test 'path_insert_after works with invalid \$PATH' {
PATH=$BATS_TEST_DIRNAME:$HOME/.local/bin:/usr/sbin::/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:
run path_insert_after.sh TEST '*/?(.)local/*'
[ "$output" = "$BATS_TEST_DIRNAME:$HOME/.local/bin:/usr/sbin::/usr/local/sb"$'\0'"in:/usr/local/bin:TEST:/usr/sbin:/usr/bin:/sbin:/bin:" ]
PATH=$BATS_TEST_DIRNAME/bin:$HOME/.local/bin:/usr/sbin::/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:
run path_insert_after TEST '*/?(.)local/*'
[ "$output" = "$BATS_TEST_DIRNAME/bin:$HOME/.local/bin:/usr/sbin::/usr/local/sb"$'\0'"in:/usr/local/bin:TEST:/usr/sbin:/usr/bin:/sbin:/bin:" ]
}

@test 'path_insert_before with match inserts before match' {
run path_insert_before.sh TEST /usr/local/bin
[ "$output" = "$BATS_TEST_DIRNAME:$HOME/.local/bin:/usr/local/sbin:TEST:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ]
run path_insert_before TEST /usr/local/bin
[ "$output" = "$BATS_TEST_DIRNAME/bin:$HOME/.local/bin:/usr/local/sbin:TEST:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ]
}

@test 'path_insert_before without match appends' {
run path_insert_before.sh TEST UNMATCHED
[ "$output" = "$BATS_TEST_DIRNAME:$HOME/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:TEST" ]
run path_insert_before TEST UNMATCHED
[ "$output" = "$BATS_TEST_DIRNAME/bin:$HOME/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:TEST" ]
}

@test 'path_remove removes literal match' {
run path_remove.sh /usr/local/bin
[ "$output" = "$BATS_TEST_DIRNAME:$HOME/.local/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin" ]
run path_remove /usr/local/bin
[ "$output" = "$BATS_TEST_DIRNAME/bin:$HOME/.local/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin" ]
}

@test 'path_remove ignores trailing slash on comparator' {
run path_remove.sh /usr/local/bin/
[ "$output" = "$BATS_TEST_DIRNAME:$HOME/.local/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin" ]
run path_remove /usr/local/bin/
[ "$output" = "$BATS_TEST_DIRNAME/bin:$HOME/.local/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin" ]
}

@test 'path_remove does not ignore trailing slash on glob' {
run path_remove.sh /usr/local/bin/ true
[ "$output" = "$BATS_TEST_DIRNAME:$HOME/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ]
run path_remove /usr/local/bin/ true
[ "$output" = "$BATS_TEST_DIRNAME/bin:$HOME/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ]
}

@test 'path_contains finds literal match' {
run path_contains.sh /usr/local/bin
run path_contains /usr/local/bin
}

@test 'path_contains ignores trailing slash on comparator' {
run path_contains.sh /usr/local/bin/
run path_contains /usr/local/bin/
}

@test 'path_contains does not ignore trailing slash on glob' {
run -1 path_contains.sh /usr/local/bin/ true
run -1 path_contains /usr/local/bin/ true
}

@test 'path_validate passes well-formed $PATH' {
run path_validate.sh
run path_validate
}

@test 'path_validate fails $PATH with nul byte' {
PATH=$PATH:$'\0'
run -1 path_validate.sh
run -1 path_validate
}

@test 'path_validate fails $PATH with empty string' {
PATH=$PATH:
run -1 path_validate.sh
run -1 path_validate
}

@test 'path_validate fails $PATH with duplicates' {
PATH=$PATH:/usr/local/bin
run -1 path_validate.sh
run -1 path_validate
}
11 changes: 1 addition & 10 deletions upkg.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
{
"assets": ["path-tools.sh"],
"commands": {
"path_append": "path_append.sh",
"path_prepend": "path_prepend.sh",
"path_insert_after": "path_insert_after.sh",
"path_insert_before": "path_insert_before.sh",
"path_remove": "path_remove.sh",
"path_contains": "path_contains.sh",
"path_validate": "path_remove.sh"
}
"name": "path-tools"
}

0 comments on commit aa9b27a

Please sign in to comment.