update publish workflow #8
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: Continuous Integration (CI) | |
| on: | |
| push: | |
| branches: | |
| - "**" | |
| pull_request: | |
| branches: | |
| - "**" | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version-file: .nvmrc | |
| - run: npm ci | |
| - run: npm run build | |
| - name: Check build output | |
| run: | | |
| test -d dist || exit 1 | |
| test -d dist/components || exit 1 | |
| test -f dist/components/components.jsonld || exit 1 | |
| test -f dist/components/context.jsonld || exit 1 | |
| - name: Save build | |
| uses: actions/upload-artifact@v6 | |
| with: | |
| name: build | |
| path: | | |
| . | |
| !node_modules | |
| retention-days: 1 | |
| test: | |
| strategy: | |
| matrix: | |
| os: [macos-latest, ubuntu-latest, windows-latest] | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version-file: .nvmrc | |
| - run: npm ci | |
| - run: npm run build | |
| - run: npx tsc --noEmit | |
| - run: npm test | |
| env: | |
| CI: true | |
| npm-publish-build: | |
| needs: [build, test] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write # Required for OIDC | |
| contents: read | |
| steps: | |
| - uses: actions/download-artifact@v7 | |
| with: | |
| name: build | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: 20.x | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Update npm to latest (required for OIDC) | |
| run: npm install -g npm@latest | |
| - uses: rlespinasse/github-slug-action@v3.x | |
| - name: Append commit hash to package version | |
| run: 'sed -i -E "s/(\"version\": *\"[^\"]+)/\1-${GITHUB_SHA_SHORT}/" package.json' | |
| - name: Disable pre- and post-publish actions | |
| run: 'sed -i -E "s/\"((pre|post)publish)/\"ignore:\1/" package.json' | |
| - name: Publish to npm | |
| if: github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]' | |
| run: npm publish --tag ${{ env.GITHUB_REF_SLUG }} | |
| npm-publish-latest: | |
| needs: [build, test, npm-publish-build] | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| permissions: | |
| id-token: write # Required for OIDC | |
| contents: read | |
| steps: | |
| - uses: actions/download-artifact@v7 | |
| with: | |
| name: build | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: 20.x | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Update npm to latest (required for OIDC) | |
| run: npm install -g npm@latest | |
| - name: Disable pre- and post-publish actions | |
| run: 'sed -i -E "s/\"((pre|post)publish)/\"ignore:\1/" package.json' | |
| - name: Publish to npm | |
| if: github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]' | |
| run: npm publish --tag latest |