0.0.8 #24
This file contains 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: CI | |
on: | |
push: | |
branches: [master] | |
pull_request: | |
branches: [master] | |
env: | |
# Setting an environment variable with the value of a configuration variable | |
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
PACKAGE_NAME: 'unknown' | |
PACKAGE_VERSION: 'unknown' | |
NPM: 'pnpm' | |
NPM_VERSION: 'unknown' | |
HAVE_COVERAGE_SCRIPT: false | |
HAVE_VALIDATE_SCRIPT: false | |
HAVE_LINT_SCRIPT: false | |
HAVE_UNIT_TEST_SCRIPT: false | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: dcarbone/install-jq-action@v2 | |
- uses: actions/checkout@v4 | |
- uses: pnpm/action-setup@v2 | |
if: env.NPM == 'pnpm' | |
with: | |
version: 9 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: '18.x' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Read package information | |
run: | | |
echo "PACKAGE_NAME=$(cat package.json | jq -r .name)" >> $GITHUB_ENV | |
echo "PACKAGE_VERSION=$(cat package.json | jq -r .version)" >> $GITHUB_ENV | |
echo "HAVE_COVERAGE_SCRIPT=$(jq 'if .scripts.coverage == null then false else true end' package.json)" >> $GITHUB_ENV | |
echo "HAVE_VALIDATE_SCRIPT=$(jq 'if .scripts.validate == null then false else true end' package.json)" >> $GITHUB_ENV | |
echo "HAVE_LINT_SCRIPT=$(jq 'if .scripts.lint == null then false else true end' package.json)" >> $GITHUB_ENV | |
echo "HAVE_UNIT_TEST_SCRIPT=$(jq 'if .scripts.test == null then false else true end' package.json)" >> $GITHUB_ENV | |
- name: Get current npmjs version for ${{env.PACKAGE_NAME}} | |
run: | | |
echo "NPM_VERSION=$(curl -s https://registry.npmjs.org/${{ env.PACKAGE_NAME }} | jq -r '."dist-tags".latest')" >> $GITHUB_ENV | |
- name: Install dependencies | |
run: ${{ env.NPM }} install | |
- name: Run validate | |
if: env.HAVE_VALIDATE_SCRIPT == 'true' | |
run: ${{ env.NPM }} run validate | |
- name: Run unit tests | |
if: env.HAVE_UNIT_TEST_SCRIPT == 'true' | |
run: ${{ env.NPM }} test | |
- name: Run linter checks | |
if: env.HAVE_LINT_SCRIPT == 'true' | |
run: ${{ env.NPM }} run lint | |
- name: Run and publish code coverage | |
if: | | |
github.ref == 'refs/heads/main' && | |
env.CC_TEST_REPORTER_ID != '' && | |
env.HAVE_COVERAGE_SCRIPT == 'true' | |
uses: paambaati/[email protected] | |
env: | |
CC_TEST_REPORTER_ID: ${{ env.CC_TEST_REPORTER_ID }} | |
with: | |
coverageCommand: ${{ env.NPM }} run coverage | |
# npm publish when PR done | |
- name: Publish ${{env.PACKAGE_NAME}} ${{env.PACKAGE_VERSION}} | |
run: ${{ env.NPM }} publish --no-git-checks --access public | |
if: | | |
github.ref == 'refs/heads/main' && | |
env.NPM_TOKEN != '' && | |
env.PACKAGE_VERSION != env.NPM_VERSION | |
env: | |
NODE_AUTH_TOKEN: ${{ env.NPM_TOKEN }} |