CI-CD #355
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-CD | |
on: | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
# run CI every Monday at 12:25 UTC | |
schedule: | |
- cron: "25 12 * * 1" | |
jobs: | |
test: | |
name: Unit tests / Node.js ${{ matrix.node-version }} / ${{ matrix.os }} | |
runs-on: ${{ matrix.os }} | |
timeout-minutes: 10 | |
strategy: | |
fail-fast: false | |
matrix: | |
os: | |
- ubuntu-latest | |
- macos-latest | |
- windows-latest | |
node-version: | |
- 16 | |
- 18 | |
- 20 | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v4 | |
- name: Install Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
cache: npm | |
- name: Install dependencies | |
run: npm ci | |
- name: Run tests | |
run: npm run coverage | |
- name: Send code coverage results to Coveralls | |
uses: coverallsapp/github-action@643bc377ffa44ace6394b2b5d0d3950076de9f63 | |
with: | |
parallel: true | |
flag-name: Node.js ${{ matrix.node-version }} / ${{ matrix.os }} | |
coverage: | |
name: Code Coverage | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
needs: test | |
steps: | |
- name: Let Coveralls know that all tests have finished | |
uses: coverallsapp/github-action@643bc377ffa44ace6394b2b5d0d3950076de9f63 | |
with: | |
parallel-finished: true | |
build: | |
name: Build and lint | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v4 | |
- name: Install Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
cache: npm | |
- name: Install development dependencies | |
run: npm ci | |
- name: Build | |
run: npm run build | |
- name: Verify no un-staged changes | |
run: | | |
git status --porcelain | |
git diff-files --quiet | |
- name: Run lints | |
run: npm run lint | |
- name: Upload publish artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: publish-artifact | |
path: lib | |
e2e: | |
name: E2E tests / Node.js ${{ matrix.node-version }} | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
needs: build | |
strategy: | |
fail-fast: false | |
matrix: | |
node-version: | |
- 16 | |
- 18 | |
- 20 | |
services: | |
verdaccio: | |
image: verdaccio/verdaccio:5 | |
ports: | |
- 4873:4873 | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v4 | |
- name: Install Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
- name: Install production dependencies | |
run: npm install --production | |
- name: Download publish artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: publish-artifact | |
path: lib | |
- id: setup | |
name: Login to local registry and set up fixture package | |
shell: bash | |
run: | | |
echo "token=$(./e2e/00-login.sh)" >> "$GITHUB_OUTPUT" | |
echo "package=$(./e2e/01-setup-package.sh ./e2e/fixture/cool\ package 0.0.1)" >> "$GITHUB_OUTPUT" | |
- name: Run CLI end-to-end test | |
shell: bash | |
env: | |
TOKEN: ${{ steps.setup.outputs.token }} | |
PACKAGE: ${{ steps.setup.outputs.package }} | |
run: | | |
./e2e/02-publish.sh "${PACKAGE}" ${TOKEN} | |
./e2e/03-verify.sh "${PACKAGE}" | |
./e2e/02-publish.sh "${PACKAGE}" ${TOKEN} | |
./e2e/01-setup-package.sh "${PACKAGE}" 0.0.2 | |
./e2e/02-publish.sh "${PACKAGE}" ${TOKEN} | |
./e2e/03-verify.sh "${PACKAGE}" | |
- id: action-no-publish | |
name: Publish with already published version | |
uses: ./ | |
with: | |
registry: http://localhost:4873 | |
package: ${{ steps.setup.outputs.package }}/package.json | |
token: ${{ steps.setup.outputs.token }} | |
- name: Check action output | |
if: ${{ steps.action-no-publish.outputs.type }} | |
run: | | |
echo "::error::Expected release type to be '', got '${{ steps.action-no-publish.outputs.type }}'" | |
exit 1 | |
- name: Create new version for Action end-to-end test | |
shell: bash | |
run: ./e2e/01-setup-package.sh "${{ steps.setup.outputs.package }}" 0.0.3 | |
- id: action-publish | |
name: Publish a new version | |
uses: ./ | |
with: | |
registry: http://localhost:4873 | |
package: ${{ steps.setup.outputs.package }}/package.json | |
token: ${{ steps.setup.outputs.token }} | |
- name: Check release output | |
if: ${{ steps.action-publish.outputs.type != 'patch' }} | |
run: | | |
echo "::error::Expected release type to be 'patch', got '${{ steps.action-publish.outputs.type }}'" | |
exit 1 | |
- id: action-publish-dry | |
name: Publish a dry run | |
uses: ./ | |
with: | |
registry: http://localhost:4873 | |
package: ${{ steps.setup.outputs.package }}/package.json | |
token: ${{ steps.setup.outputs.token }} | |
dry-run: true | |
- name: Check release output | |
if: ${{ steps.action-publish-dry.outputs.type }} | |
run: | | |
echo "::error::Expected release type to be '', got '${{ steps.action-publish-dry.outputs.type }}'" | |
exit 1 | |
deploy: | |
if: ${{ github.ref == 'refs/heads/main' }} | |
name: Publish | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
permissions: | |
contents: read | |
id-token: write | |
needs: | |
- test | |
- build | |
- e2e | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v4 | |
- name: Install Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
- name: Download publish artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: publish-artifact | |
path: lib | |
- name: Publish to NPM | |
uses: ./ | |
with: | |
token: ${{ secrets.NPM_TOKEN }} |