Skip to content

Commit

Permalink
Initial 0.1.0 release
Browse files Browse the repository at this point in the history
Signed-off-by: Torsten Long <[email protected]>
  • Loading branch information
razziel89 authored Jul 28, 2023
1 parent 4ba9392 commit 46474b6
Show file tree
Hide file tree
Showing 21 changed files with 2,293 additions and 0 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/test-lint-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Copyright (c) 2022 Robert Bosch GmbH and its subsidiaries.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

name: test, lint & deploy

on:
push:
pull_request:
# Set workflow_dispatch to enable triggering the workflow in the web UI.
workflow_dispatch:

defaults:
run:
shell: bash

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

jobs:
build-deploy:
timeout-minutes: 8

runs-on: ubuntu-22.04

steps:
- name: Install system dependencies
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo apt-get update -qq
sudo apt-get install -qqy --no-install-recommends \
ca-certificates coreutils curl git jq kcov make shellcheck
- name: Install bats
run: |
git clone https://github.com/bats-core/bats-core.git
sudo ./bats-core/install.sh /usr/local
rm -rf bats-core
- name: Disable git config safety checks for this repository
run: |
git config --global --add safe.directory "$(pwd)"
- name: Install shfmt
env:
VERSION: 3.7.0
SHA256: 0264c424278b18e22453fe523ec01a19805ce3b8ebf18eaf3aadc1edc23f42e3
URL: https://github.com/mvdan/sh/releases/download
run: |
curl -o shfmt --location \
"${URL}/v${VERSION}/shfmt_v${VERSION}_linux_amd64"
echo "${SHA256} shfmt" | sha256sum -c
chmod +x shfmt
sudo mv shfmt /usr/local/bin/shfmt
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Test Package
run: make test

- name: Lint Package
run: make lint

- name: Build Package
run: make build

- name: Publish package on GH (only tags)
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: softprops/action-gh-release@v1
with:
files: shellmock.bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Deployable.
/shellmock.bash
/.coverage
21 changes: 21 additions & 0 deletions 3rd-party-licenses.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!---
Copyright (c) 2022 - for information on the respective copyright owner
see the NOTICE file or the repository
https://github.com/boschresearch/shellmock
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
-->

# Third-party Licences

Shellmock does not include any third-party software.
2 changes: 2 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Default code owners:
* @razziel89
161 changes: 161 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<!---
Copyright (c) 2022 - for information on the respective copyright owner
see the NOTICE file or the repository
https://github.com/boschresearch/shellmock
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
-->

# Contributing

Want to contribute?
Great!
You can do so through the standard GitHub pull request model.
For large contributions we do encourage you to file a ticket in the GitHub
issues tracking system prior to any code development to coordinate with the
Shellmock team early in the process.
Coordinating up front helps to avoid frustration later on.
Please make sure to:

- add tests for all new or updated code
- make sure existing tests work by running `make test`
- make sure the code follows this repository's guidelines by running the
commands `make format` and `make lint`

Your contribution must be licensed under the Apache-2.0 license, the license
used by this project.

## Add / retain copyright notices

Include a copyright notice and license in each new file to be contributed,
consistent with the style used by this project.
If your contribution contains code under the copyright of a third party,
document its origin, license, and copyright holders.

## Sign your work

This project tracks patch provenance and licensing using the Developer
Certificate of Origin 1.1 (DCO) from [developercertificate.org][DCO] and
Signed-off-by tags initially developed by the Linux kernel project.

```text
Developer Certificate of Origin
Version 1.1
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129
Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
```

With the sign-off in a commit message you certify that you authored the patch or
otherwise have the right to submit it under an open source license.
The procedure is simple: To certify above Developer's Certificate of Origin 1.1
for your contribution just append a line

```text
Signed-off-by: Random J Developer <[email protected]>
```

to every commit message using your real name or your pseudonym and a valid email
address.

If you have set your `user.name` and `user.email` git config entries, you can
automatically sign the commit by running the git-commit command with the `-s`
option.
There may be multiple sign-offs if more than one developer was involved in
authoring the contribution.

For a more detailed description of this procedure, please see
[SubmittingPatches], which was extracted from the Linux kernel project, and
which is stored in an external repository.

### Individual vs. Corporate Contributors

Often employers or academic institution have ownership over code that is
written in certain circumstances, so please do due diligence to ensure that
you have the rights to submit the code.

If you are a developer who is authorized to contribute to Shellmock on behalf of
your employer, then please use your corporate email address in the Signed-off-by
tag.
Otherwise please use a personal email address.

## Maintain Copyright holder / Contributor list

Each contributor is responsible for identifying themselves in the
[NOTICE](./NOTICE) file, the project's list of copyright holders and authors.
Please add the respective information corresponding to the Signed-off-by tag as
part of your first pull request.

If you are a developer who is authorized to contribute to Shellmock on behalf of
your employer, then add your company / organization to the list of copyright
holders in the [NOTICE](./NOTICE) file.
As author of a corporate contribution you can also add your name and corporate
email address as in the Signed-off-by tag.

If your contribution is covered by this project's DCO's clause "(c) The
contribution was provided directly to me by some other person who certified (a)
or (b) and I have not modified it", please add the appropriate copyright
holder(s) to the [NOTICE](./NOTICE) file as part of your contribution.

[DCO]: https://developercertificate.org/
[SubmittingPatches]: https://github.com/wking/signed-off-by/blob/7d71be37194df05c349157a2161c7534feaf86a4/Documentation/SubmittingPatches

<!---
Copyright (c) 2022 - for information on the respective copyright owner
see the NOTICE file or the repository
https://github.com/boschresearch/shellmock
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
-->
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down
88 changes: 88 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Copyright (c) 2022 - for information on the respective copyright owner
# see the NOTICE file or the repository
# https://github.com/boschresearch/shellmock
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

SHELL := /bin/bash -euo pipefail

default: build

.PHONY: check-dependencies
check-dependencies:
command -v bash &>/dev/null || (echo "ERROR, please install bash" >&2; exit 1)
command -v bats &>/dev/null || (echo "ERROR, please install bats" >&2; exit 1)
command -v find &>/dev/null || (echo "ERROR, please install find" >&2; exit 1)
command -v shellcheck &>/dev/null || (echo "ERROR, please install shellcheck" >&2; exit 1)
command -v shfmt &>/dev/null || (echo "ERROR, please install shfmt" >&2; exit 1)
command -v jq &>/dev/null || (echo "ERROR, please install jq" >&2; exit 1)
command -v kcov &>/dev/null || (echo "ERROR, please install kcov " >&2; exit 1)

SHELLCHECK_OPTS := --enable=add-default-case,avoid-nullary-conditions,quote-safe-variables,require-variable-braces
export SHELLCHECK_OPTS

.PHONY: lint
lint:
shellcheck ./bin/* ./lib/* ./tests/*
$(MAKE) check-format

.PHONY: test
test: build
bats --print-output-on-failure ./tests/*.bats

COVERAGE_FAILED_MESSAGE := \
Cannot generate coverage reports as root user because kcov is not \
compatible with current versions of bash when run as root, also see \
https://github.com/SimonKagstrom/kcov/issues/234\#issuecomment-453929674

coverage: test
if [[ "$$(id -ru)" -eq 0 ]]; then \
echo >&2 "$(COVERAGE_FAILED_MESSAGE)"; exit 1; \
fi
# Generate coverage reports.
kcov --bash-dont-parse-binary-dir --clean --include-path=. ./.coverage \
bats --print-output-on-failure ./tests/*.bats
# Analyse output of coverage reports and fail if not all files have been
# covered of if coverage is not high enough.
awk \
-v min_cov="92" \
-v tot_num_files="1" \
'BEGIN{num_files=0; cov=0;} \
$$1 ~ /"file":/{num_files++} \
$$1 ~ /"covered_lines":/{cov=$$2} \
$$1 ~ /"total_lines":/{tot_cov=$$2} \
END{ \
if(num_files!=tot_num_files){ \
printf("Not all files covered: %d < %d\n", num_files, tot_num_files); exit 1 \
} \
} \
END{ \
if(cov/tot_cov < min_cov/100){ \
printf("Coverage too low: %.2f < %.2f\n", cov/tot_cov, min_cov/100); exit 1 \
} \
}' < <(jq < $$(ls -d1 .coverage/bats.*/coverage.json) | sed 's/,$$//')

format:
shfmt -w -bn -i 2 -sr -ln bash ./bin/* ./lib/*
shfmt -w -bn -i 2 -sr -ln bats ./tests/*

check-format:
shfmt -d -bn -i 2 -sr -ln bash ./bin/* ./lib/*
shfmt -d -bn -i 2 -sr -ln bats ./tests/*

build:
./generate_deployable.sh

clean:
rm -f shellmock.bash
rm -fr .coverage
Loading

0 comments on commit 46474b6

Please sign in to comment.