Coder Social home page Coder Social logo

mig4 / setup-bats Goto Github PK

View Code? Open in Web Editor NEW
27.0 2.0 9.0 1.39 MB

GitHub Action to setup BATS testing framework

License: MIT License

TypeScript 90.62% JavaScript 8.05% Shell 1.34%
action github-actions github-action bats testing testing-framework setup hacktoberfest

setup-bats's Introduction

tag-badge CI

Setup BATS ๐Ÿฆ‡

A :octocat: GitHub Action to setup BATS testing framework.

Usage ๐Ÿš€

A sample workflow to run tests using BATS (.github/workflows/ci.yml):

name: "CI"
on: [push, pull_request]
jobs:
  build:
    name: build
    runs-on: ubuntu-latest
    steps:

      - name: Setup BATS
        uses: mig4/setup-bats@v1
        with:
          bats-version: 1.2.1

      - name: Check out code
        uses: actions/checkout@v1

      - name: Test
        run: bats -r .

Options ๐ŸŽจ

Options available as keys in with block

  • bats-version (string): version of BATS to setup, defaults to 1.2.1 if not set

Platforms ๐Ÿ–ฅ

So far this action has only been tested on Linux environments.

Contributing ๐Ÿค

See known issues, if you found one that's not on the list or have a suggestion for improvement, open a new issue. If you can, fork and send a PR, it will be appreciated ๐Ÿ’–.

Hacking ๐Ÿงฐ

Building

Install the dependencies

$ npm install

Build the typescript, apply formatting, lint and package the code for distribution and run unit tests:

$ npm run all

Run the tests separately โœ”๏ธ

$ npm test
...
 PASS  __tests__/installer.test.ts
  installer tests
    โœ“ Acquires version of BATS if no matching version is installed (1051ms)
    โœ“ Throws if no matching version of BATS can be found (674ms)

Code

The action.yml file defines the inputs and output, description, etc. of the action.

See the documentation:

Publishing to a distribution branch

Actions are run from GitHub repos so the branch which will be used at runtime needs to have the dist/ folder checked-in. It's recommended for users to only refer to released versions instead of consuming master directly.

The distribution is created with ncc which can be invoked via:

$ npm run package
$ git add dist
$ git commit -a -m "prod package"

Now to release a new minor/patch versions (replace .x.y as appropriate):

# update "version" property in `package.json`
$ npm install
$ npm run all
$ git add -A
$ git commit -v -m "Release v1.x.y"
$ git push
$ git tag -s v1.x.y
$ git tag -fs v1 -m "Update v1 tag"
$ git push --tags --force

For the tag to be published to marketplace you need to create a release from it which you can do by going into Releases in GitHub UI, then Tags and clicking the menu next to the newly created tag and select Create release. Alternatively use the URL (replace x.y as appropriate): https://github.com/mig4/setup-bats/releases/new?tag=v1.x.y

The action is now published! ๐Ÿš€

See the versioning documentation

Acknowledgements ๐Ÿ‘

License ๐Ÿ“

license-badge

setup-bats's People

Contributors

dependabot[bot] avatar mig4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

setup-bats's Issues

GITHUB_TOKEN permissions used by this action

At https://github.com/step-security/secure-workflows we are building a knowledge-base (KB) of GITHUB_TOKEN permissions needed by different GitHub Actions. When developers try to set minimum token permissions for their workflows, they can use this knowledge-base instead of trying to research permissions needed by each GitHub Action they use.

Below you can see the KB of your GITHUB Action.

name: 'Setup BATS testing framework' # mig4/setup-bats
# GITHUB_TOKEN not used

If you think this information is not accurate, or if in the future your GitHub Action starts using a different set of permissions, please create an issue at https://github.com/step-security/secure-workflows/issues to let us know.

This issue is automatically created by our analysis bot, feel free to close after reading :)

References:

GitHub asks users to define workflow permissions, see https://github.blog/changelog/2021-04-20-github-actions-control-permissions-for-github_token/ and https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token for securing GitHub workflows against supply-chain attacks.

Setting minimum token permissions is also checked for by Open Source Security Foundation (OpenSSF) Scorecards. Scorecards recommend using https://github.com/step-security/secure-workflows so developers can fix this issue in an easier manner.

Include bats-assert and bats-support

It would be great to have these bats libraries installed by this action to make it easier to write tests with rich assertions.

Currently I am running these bash commands in a subsequent step to install the libraries relative to my bats file, as shown in the installation documentation.

apt-get install --assume-yes wget unzip

wget https://github.com/bats-core/bats-assert/archive/master.zip -O assert.zip
unzip assert.zip
mv bats-assert-master/ bats-assert/

wget https://github.com/bats-core/bats-support/archive/master.zip -O support.zip
unzip support.zip
mv bats-support-master/ bats-support/

Error: Cannot find module '@actions/core'

Granted, this is the first time I'm trying out Github Actions and I could well be doing things wrong entirely. But while I could use and run a shellcheck action from another repo successfully, this action here fails with the above error.
Full log output here:

2019-11-28T22:03:30.1313172Z ##[section]Starting: Request a runner to run this job
2019-11-28T22:03:30.3575929Z Requesting a hosted runner in current repository's account/organization with labels: 'ubuntu-latest', require runner match: True
2019-11-28T22:03:30.6525947Z Labels matched hosted runners has been found, waiting for one of them get assigned for this job.
2019-11-28T22:03:30.7514875Z ##[section]Finishing: Request a runner to run this job
2019-11-28T22:03:39.5813125Z Current runner version: '2.161.0'
2019-11-28T22:03:39.5814332Z Prepare workflow directory
2019-11-28T22:03:39.6024050Z Prepare all required actions
2019-11-28T22:03:39.6051476Z Download action repository 'mig4/setup-bats@master'
2019-11-28T22:03:41.8063239Z Download action repository 'actions/checkout@v1'
2019-11-28T22:03:42.0128588Z ##[group]Run mig4/setup-bats@master
2019-11-28T22:03:42.0129010Z with:
2019-11-28T22:03:42.0129260Z   bats-version: 1.1.0
2019-11-28T22:03:42.0129388Z ##[endgroup]
2019-11-28T22:03:42.3464864Z internal/modules/cjs/loader.js:626
2019-11-28T22:03:42.3465088Z     throw err;
2019-11-28T22:03:42.3465237Z     ^
2019-11-28T22:03:42.3465313Z 
2019-11-28T22:03:42.3466136Z Error: Cannot find module '@actions/core'
2019-11-28T22:03:42.3466306Z Require stack:
2019-11-28T22:03:42.3466701Z - /home/runner/work/_actions/mig4/setup-bats/master/lib/setup-bats.js
2019-11-28T22:03:42.3466887Z     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:623:15)
2019-11-28T22:03:42.3467096Z     at Function.Module._load (internal/modules/cjs/loader.js:527:27)
2019-11-28T22:03:42.3467263Z     at Module.require (internal/modules/cjs/loader.js:681:19)
2019-11-28T22:03:42.3467423Z     at require (internal/modules/cjs/helpers.js:16:16)
2019-11-28T22:03:42.3467892Z     at Object.<anonymous> (/home/runner/work/_actions/mig4/setup-bats/master/lib/setup-bats.js:18:27)
2019-11-28T22:03:42.3468078Z     at Module._compile (internal/modules/cjs/loader.js:774:30)
2019-11-28T22:03:42.3468243Z     at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
2019-11-28T22:03:42.3468411Z     at Module.load (internal/modules/cjs/loader.js:641:32)
2019-11-28T22:03:42.3468555Z     at Function.Module._load (internal/modules/cjs/loader.js:556:12)
2019-11-28T22:03:42.3468719Z     at Function.Module.runMain (internal/modules/cjs/loader.js:837:10) {
2019-11-28T22:03:42.3469081Z   code: 'MODULE_NOT_FOUND',
2019-11-28T22:03:42.3489216Z   requireStack: [
2019-11-28T22:03:42.3489845Z     '/home/runner/work/_actions/mig4/setup-bats/master/lib/setup-bats.js'
2019-11-28T22:03:42.3490037Z   ]
2019-11-28T22:03:42.3490182Z }
2019-11-28T22:03:42.3501078Z ##[error]Node run failed with exit code 1
2019-11-28T22:03:42.3544191Z Cleaning up orphan processes

Please let me know if I can provide more information to help solve this. And thanks for creating this action.

Add integration test

Add a step to CI to dogfood the action to setup BATS and then run a simple bats test (doesn't matter what it does) to ensure everything actually works in practice.

Fix the problem matcher

AFAICT the purpose of a problem matcher is to capture errors in the output, parse them and provide links to location where the problem originated. Which sounds useful for BATS - we could e.g. link to failing test definition.

However, I'm not sure if BATS provides enough information to do that, it seems you may need at least a file and line number to do that, and bats only provides test name and (in --tap mode) sequence number which I'm not sure if you can correlate back to location.

Also it's not quite clear what the schema of the JSON file for defining problem matchers is, the best thing I could find so far is actions/toolkit#56 which points to this vscode doc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.