64 lines
2.0 KiB
YAML
64 lines
2.0 KiB
YAML
name: CI & Test NaxOS Management API
|
|
|
|
on:
|
|
push:
|
|
branches: [ main ]
|
|
pull_request:
|
|
branches: [ main ]
|
|
|
|
permissions:
|
|
contents: write
|
|
packages: write
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout Repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 22
|
|
|
|
- name: Install Dependencies
|
|
run: npm ci || npm install
|
|
|
|
- name: Typecheck
|
|
run: npx tsc --noEmit
|
|
|
|
- name: Run Unit Tests
|
|
run: npm test
|
|
|
|
- name: Build Management Daemon
|
|
run: npm run build
|
|
|
|
- name: Publish Package to Gitea Packages
|
|
run: |
|
|
npm pack
|
|
TGZ_FILE=$(ls naxos-api-*.tgz | head -n 1)
|
|
echo "Packaging $TGZ_FILE to Gitea Packages registry..."
|
|
TOKEN="${{ secrets.PACKAGE_TOKEN }}"
|
|
if [ -z "$TOKEN" ]; then
|
|
TOKEN="${{ secrets.GITEA_TOKEN }}"
|
|
fi
|
|
RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" -X PUT \
|
|
-H "Authorization: token ${TOKEN}" \
|
|
--upload-file "$TGZ_FILE" \
|
|
"${{ github.server_url }}/api/packages/naxos/generic/naxos-api/1.0.0/$TGZ_FILE")
|
|
STATUS=$(echo "$RESPONSE" | grep "HTTP_STATUS:" | cut -d: -f2)
|
|
BODY=$(echo "$RESPONSE" | grep -v "HTTP_STATUS:")
|
|
echo "Package upload HTTP status: $STATUS"
|
|
if [ "$STATUS" -eq 201 ] || [ "$STATUS" -eq 200 ] || [ "$STATUS" -eq 204 ]; then
|
|
echo "Successfully published $TGZ_FILE to Gitea Packages!"
|
|
elif [ "$STATUS" -eq 409 ]; then
|
|
echo "Package version 1.0.0 already published in Gitea Packages: $BODY"
|
|
else
|
|
echo "Failed to publish package to Gitea Packages ($STATUS): $BODY"
|
|
exit 1
|
|
fi
|
|
|
|
echo "//git.lholz.de/api/packages/naxos/npm/:_authToken=${TOKEN}" >> ~/.npmrc
|
|
npm publish || echo "NPM package published or exists in registry"
|