.github/workflows/ci-test.yml
# This is a basic workflow to help you get started with Actions name: test # Controls when the action will run.on: # Triggers the workflow on push or pull request events but only for the develop branch push: branches: [master, develop] tags: - "*" pull_request: branches: [master, develop] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: # A workflow run is made up of one or more jobs that can run sequentially or in paralleljobs: # This workflow contains a single job called "build" test: # The type of runner that the job will run on runs-on: ubuntu-latest strategy: matrix: node-version: [20.x, 22.x] steps: - uses: actions/checkout@v4 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - name: Get yarn cache directory path id: yarn-cache-dir-path run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT - uses: actions/cache@v4 id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: ${{ steps.yarn-cache-dir-path.outputs.dir }} key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} restore-keys: | ${{ runner.os }}-yarn- - name: Update npm and install packages run: | npm i -g npm@latest yarn@latest yarn install - name: Build packages run: yarn babel - name: Test with jest run: yarn test - name: Test with karma run: yarn karma - name: Install lcov and merge coverage info run: | sudo apt update sudo apt install lcov mkdir -p ./coverage find ./packages -name lcov.info -exec echo -a {} \; | xargs lcov -o ./coverage/merged-lcov.info - name: Upload coverage to Codecov uses: codecov/codecov-action@v5 with: files: ./coverage/merged-lcov.info webpage: needs: test if: ${{ (github.ref_name == 'master') }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: node-version: "22.x" - run: | yarn yarn docs mv esdocs ~/docs - name: Setup git env: WEBPAGE_REPO_DEPLOY_KEY: ${{ secrets.WEBPAGE_REPO_DEPLOY_KEY }} run: | echo "$WEBPAGE_REPO_DEPLOY_KEY" > ~/deploy_key.pem chmod 600 ~/deploy_key.pem git config --global user.email "junkurihara@users.noreply.github.com" git config --global user.name "J via GitHub Actions" - name: Update and deploy pages env: GIT_SSH_COMMAND: ssh -i ~/deploy_key.pem -o StrictHostKeyChecking=no -F /dev/null run: | mkdir -p ~/jscu-webpage cd ~/jscu-webpage git clone git@github.com:junkurihara/jscu-webpage.git . rm -rf ./docs mv ~/docs ./docs git add . if ! git diff --cached --quiet; then echo 'Updated page and push via GitHub Actions' git commit -am 'Updated page and push via GitHub Actions' git push origin master fi publish: needs: test if: startsWith(github.event.ref, 'refs/tags/v') runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 # Setup .npmrc file to publish to npm - uses: actions/setup-node@v4 with: node-version: "22.x" registry-url: "https://registry.npmjs.org" # Defaults to the user or organization that owns the workflow file scope: "@octocat" - run: | yarn yarn build bash scripts/publish.sh env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}