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 uses: actions/upload-artifact@v4 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 }} run: | if [ -z "${GITEA_TOKEN}" ]; then echo "GITEA_TOKEN is not configured; skipping Gitea release." exit 0 fi VERSION="$(node -p "require('./package.json').version")" API="${GITEA_SERVER_URL%/}/api/v1/repos/${GITEA_REPOSITORY}/releases" curl -sSf \ -H "Authorization: token ${GITEA_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"