Merge pull request #14 from GhostTypes/update-readme-badges-docs-link #15
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: Build and Publish Package | |
| on: | |
| push: | |
| branches: [ main ] | |
| tags: [ 'v*' ] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| build-and-publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| registry-url: 'https://npm.pkg.github.com' | |
| scope: '@ghosttypes' | |
| - name: Install dependencies | |
| run: npm install | |
| - name: Build | |
| run: npm run build | |
| - name: Set version | |
| id: set_version | |
| run: | | |
| if [[ "${{ github.ref }}" == refs/tags/v* ]]; then | |
| # If this is a tag push, use the tag version | |
| TAG=${GITHUB_REF#refs/tags/} | |
| VERSION=${TAG#v} | |
| else | |
| # If this is not a tag push, use the current version and add timestamp | |
| CURRENT_VERSION=$(node -p "require('./package.json').version") | |
| TIMESTAMP=$(date +%Y%m%d%H%M%S) | |
| VERSION="${CURRENT_VERSION}-${TIMESTAMP}" | |
| fi | |
| echo "Using version: $VERSION" | |
| npm version $VERSION --no-git-tag-version | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Publish to GitHub Packages | |
| run: npm publish | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Report error details if failed | |
| if: failure() | |
| run: | | |
| echo "::error::Package publish failed. Please check authentication and configuration." | |
| echo "::group::NPM Config" | |
| npm config list | |
| echo "::endgroup::" | |
| echo "::group::Repository Info" | |
| echo "Owner: ${{ github.repository_owner }}" | |
| echo "Repo: ${{ github.repository }}" | |
| echo "::endgroup::" |