name: CI / CD on: push: branches: - "**" pull_request: branches: - main jobs: build: name: Test and Build runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Setup pnpm uses: pnpm/action-setup@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: "24" registry-url: "https://registry.npmjs.org" - name: Resolve pnpm store id: pnpm-store run: echo "STORE_PATH=$(pnpm store path)" >> "$GITHUB_OUTPUT" - name: Cache pnpm store uses: actions/cache@v4 with: path: ${{ steps.pnpm-store.outputs.STORE_PATH }} key: ${{ runner.os }}-pnpm-store-${{ hashFiles('package.json', 'pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-pnpm-store- - name: Install dependencies run: pnpm install --no-frozen-lockfile - name: Test run: pnpm test - name: Build run: pnpm build - name: Package dist run: zip -r dist.zip dist package.json README.md - name: Upload dist artifact to Gitea uses: actions/upload-artifact@v3 with: name: shsf-cli-dist path: dist.zip publish: name: Publish needs: build if: github.event_name == 'push' && github.ref == 'refs/heads/main' runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Setup pnpm uses: pnpm/action-setup@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: "24" registry-url: "https://registry.npmjs.org" - name: Resolve pnpm store id: pnpm-store run: echo "STORE_PATH=$(pnpm store path)" >> "$GITHUB_OUTPUT" - name: Cache pnpm store uses: actions/cache@v4 with: path: ${{ steps.pnpm-store.outputs.STORE_PATH }} key: ${{ runner.os }}-pnpm-store-${{ hashFiles('package.json', 'pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-pnpm-store- - name: Install dependencies run: pnpm install --no-frozen-lockfile - name: Build run: pnpm build - name: Publish to npm run: | if [ -z "${NODE_AUTH_TOKEN}" ]; then echo "NPM_TOKEN is not configured; skipping npm publish." exit 0 fi pnpm publish --no-git-checks env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - name: Package release archive run: zip -r dist.zip dist package.json README.md - name: Create Gitea release env: GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | TOKEN="${GITEA_TOKEN:-${GITHUB_TOKEN:-}}" if [ -z "${TOKEN}" ]; then echo "No Gitea token is configured; skipping Gitea release." exit 0 fi VERSION="$(node -p "require('./package.json').version")" SERVER_URL="${GITEA_SERVER_URL:-${GITHUB_SERVER_URL}}" REPOSITORY="${GITEA_REPOSITORY:-${GITHUB_REPOSITORY}}" API="${SERVER_URL%/}/api/v1/repos/${REPOSITORY}/releases" RELEASE_JSON="$(curl -sSf \ -H "Authorization: token ${TOKEN}" \ -H "Content-Type: application/json" \ -d "{\"tag_name\":\"v${VERSION}\",\"target_commitish\":\"${GITHUB_SHA}\",\"name\":\"v${VERSION}\",\"body\":\"Automated SHSF CLI release v${VERSION}\",\"draft\":false,\"prerelease\":false}" \ "$API")" RELEASE_ID="$(node -e "const fs=require('fs'); const data=JSON.parse(fs.readFileSync(0, 'utf8')); process.stdout.write(String(data.id));" <<< "${RELEASE_JSON}")" curl -sSf \ -H "Authorization: token ${TOKEN}" \ -F "attachment=@dist.zip" \ "${API}/${RELEASE_ID}/assets?name=dist.zip"