name: Publish npm packages on: push: tags: - 'v*' release: types: - published jobs: publish: name: Publish shared npm packages runs-on: ubuntu-latest permissions: contents: read steps: - name: Checkout source uses: actions/checkout@v4 - name: Set up Node.js uses: actions/setup-node@v4 with: node-version: 22 cache: npm - name: Install and build packages run: | npm ci npm run build - name: Run the lint and test checks that gate pull requests run: | npm run lint npm test - name: Configure Gitea npm registry env: PACKAGE_REGISTRY_USERNAME: ${{ secrets.PACKAGE_REGISTRY_USERNAME }} PACKAGE_REGISTRY_TOKEN: ${{ secrets.PACKAGE_REGISTRY_TOKEN }} run: | set -euo pipefail if [ -z "$PACKAGE_REGISTRY_USERNAME" ] || [ -z "$PACKAGE_REGISTRY_TOKEN" ]; then echo 'PACKAGE_REGISTRY_USERNAME and PACKAGE_REGISTRY_TOKEN secrets are required.' >&2 exit 1 fi npmrc_path="$RUNNER_TEMP/gitea-npmrc" umask 077 { printf '@gabriel20xx:registry=https://repos.gfranz.ch/api/packages/Gabriel20xx/npm/\n' printf '//repos.gfranz.ch/api/packages/Gabriel20xx/npm/:_authToken=%s\n' "$PACKAGE_REGISTRY_TOKEN" printf 'always-auth=true\n' } > "$npmrc_path" printf 'NPM_CONFIG_USERCONFIG=%s\n' "$npmrc_path" >> "$GITHUB_ENV" - name: Publish npm packages env: PACKAGE_REGISTRY_USERNAME: ${{ secrets.PACKAGE_REGISTRY_USERNAME }} PACKAGE_REGISTRY_TOKEN: ${{ secrets.PACKAGE_REGISTRY_TOKEN }} NPM_REGISTRY: https://repos.gfranz.ch/api/packages/Gabriel20xx/npm/ run: | set -euo pipefail if [ -z "$PACKAGE_REGISTRY_USERNAME" ] || [ -z "$PACKAGE_REGISTRY_TOKEN" ]; then echo 'PACKAGE_REGISTRY_USERNAME and PACKAGE_REGISTRY_TOKEN secrets are required.' >&2 exit 1 fi for package in \ @gabriel20xx/design-tokens \ @gabriel20xx/web-ui \ @gabriel20xx/node-backend; do version="$(npm pkg get version --workspace="$package" | tr -d '"[:space:]')" package_path="${package//@/%40}" package_path="${package_path//\//%2f}" metadata_file="$(mktemp)" metadata_status="$(curl --silent --show-error --fail-with-body \ --user "$PACKAGE_REGISTRY_USERNAME:$PACKAGE_REGISTRY_TOKEN" \ --output "$metadata_file" \ --write-out '%{http_code}' \ "${NPM_REGISTRY}${package_path}" || true)" case "$metadata_status" in 200) if grep -Fq "\"$version\"" "$metadata_file"; then echo "$package@$version is already published; skipping." rm -f "$metadata_file" continue fi ;; 404) ;; *) cat "$metadata_file" >&2 echo "Gitea npm metadata lookup failed with HTTP status $metadata_status." >&2 exit 1 ;; esac npm publish --workspace="$package" --registry="$NPM_REGISTRY" rm -f "$metadata_file" done