ci: clean code #194
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: cicd | |
| # Run the workflow when a Pull Request is opened or when changes are pushed to master | |
| on: | |
| workflow_dispatch: | |
| pull_request: | |
| push: | |
| branches: [ master ] | |
| jobs: | |
| lint-commit: | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: lint commit message of this pull request | |
| uses: wagoid/commitlint-github-action@v2 | |
| lint: | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| cache: 'npm' | |
| - name: Install | |
| run: npm ci | |
| - name: shellcheck-shfmt | |
| run: npm run lint | |
| test: | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| # Fetch the latest commit | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| # Run tests | |
| - name: shellspec-kcov | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y bash kcov netcat-openbsd lsof | |
| command -v kcov | |
| curl -fsSL https://git.io/shellspec | sh -s 0.27.2 --yes | |
| export PATH="$HOME/.local/lib/shellspec:$PATH" | |
| bash -c 'echo BASH_VERSION: $BASH_VERSION' | |
| bash shellspec --kcov -f t spec/*.spec.sh | |
| - name: codecov.io | |
| run: bash <(curl -s https://codecov.io/bash) | |
| - name: failed if coverage not 100% | |
| run: | | |
| cat coverage/coverage.json | |
| percent=$(jq '.percent_covered|tonumber|floor' coverage/coverage.json) | |
| if (( $(echo "${percent} == 100" | bc -l) )); then | |
| echo "The coverage is OK." | |
| exit 0 | |
| fi | |
| echo "The coverage should be 100%." | |
| exit 1 | |
| semantic-release-preview: | |
| runs-on: ubuntu-22.04 | |
| # Waits for test jobs to complete | |
| needs: [lint-commit,lint,test] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| cache: 'npm' | |
| - name: Install | |
| run: npm ci | |
| - name: semantic-release dry run to preview of the pending release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
| DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
| run: npx semantic-release --dry-run | |
| semantic-release: | |
| # Only release on push to master | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/master' | |
| runs-on: ubuntu-22.04 | |
| # Waits for test jobs to complete | |
| needs: [semantic-release-preview] | |
| permissions: | |
| contents: write | |
| packages: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: true | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| cache: 'npm' | |
| - name: Install | |
| run: npm ci | |
| - name: Setup git identity | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Login to Docker Hub | |
| run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin | |
| - name: semantic-release | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
| DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
| run: npx semantic-release |