Laterano/.gitea/workflows/publishToNpm.yaml
Astrian Zheng ea236c385e
Some checks failed
Publish to npm / quality (push) Successful in 25s
Publish to npm / failed-webhook (push) Has been skipped
Publish to npm / publish (push) Failing after 25s
refactor: enhance webhook notifications for quality checks and package publishing
2025-05-21 16:18:02 +10:00

84 lines
2.7 KiB
YAML

name: Publish to npm
on:
push:
branches:
- main
- dev
jobs:
quality:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '22'
- name: Install dependencies
run: npm ci
- name: Run Biome
run: npm run quality-check
if: always()
outputs:
status: ${{ job.status }}
failed-webhook:
needs: quality
runs-on: ubuntu-latest
if: ${{ needs.quality.outputs.status == 'failure' }}
steps:
- name: Send webhook
run: |
QUALITY_CHECK_GROUP="Laterano CI/CD"
QUALITY_CHECK_TITLE="Quality Check Failed"
QUALITY_CHECK_MESSAGE="Quality check failed for commit ${{ gitea.sha }} in ${{ gitea.repository }}"
curl -X POST "https://bark.nas.astrian.moe/${{ secrets.BARK_TOKEN }}/${QUALITY_CHECK_TITLE}/${QUALITY_CHECK_MESSAGE}?group=${QUALITY_CHECK_GROUP}"
publish:
runs-on: ubuntu-latest
needs: quality
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '22'
registry-url: 'https://registry.npmjs.org/'
- name: Install dependencies
run: npm ci
- name: Determine package name
id: package_name
run: |
if [ "${{ gitea.ref }}" == "refs/heads/main" ]; then
echo "PACKAGE_NAME=laterano" >> $GITEA_ENV
echo "ACCESS_LEVEL=public" >> $GITEA_ENV
elif [ "${{ gitea.ref }}" == "refs/heads/dev" ]; then
echo "PACKAGE_NAME=@astrian/laterano-dev" >> $GITEA_ENV
echo "ACCESS_LEVEL=restricted" >> $GITEA_ENV
fi
- name: Update package.json for dev releases
if: GITEA.ref == 'refs/heads/dev'
run: |
jq --arg name "@astrian/laterano-dev" '.name=$name' package.json > temp.json && mv temp.json package.json
jq --arg version "0.0.0-dev.$(date +%s)" '.version=$version' package.json > temp.json && mv temp.json package.json
- name: Publish to npm
run: npm publish --access $ACCESS_LEVEL
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Send webhook
run: |
PACKAGE_NAME="${{ steps.package_name.outputs.PACKAGE_NAME }}"
MSG_GROUP="Laterano CI/CD"
MSG_TITLE="Package Published"
MSG_MESSAGE="Package $PACKAGE_NAME has been published to npm."
curl -X POST "https://bark.nas.astrian.moe/${{ secrets.BARK_TOKEN }}/${MSG_TITLE}/${MSG_MESSAGE}?group=${MSG_GROUP}"