Cockatrice/.github/workflows/protocol-publish.yml
ZeldaZach b870ce0a4a
[Protocol] Inline package assembly, fix cmake-format, add workflow_dispatch
- Replace the custom Node packaging script with a flat inline step
  (cp the .proto glob, cp the static files, npm version) so the
  workflow speaks the same shell idiom as the other workflows.
- Promote package.json and README.md to static files under
  libcockatrice_protocol/npm/ so contributors edit them in-place.
- Re-format libcockatrice_protocol/CMakeLists.txt per .cmake-format.json.
- Add workflow_dispatch (manual run; optional version input) and
  timeout-minutes: 10.
- Drop --provenance from npm publish: GitHub Packages doesn't
  attest Sigstore provenance.
2026-05-23 13:15:33 -04:00

101 lines
3 KiB
YAML

name: Publish @cockatrice/protocol
on:
release:
types:
- released # stable releases only; prereleases intentionally skipped
pull_request:
branches:
- master
paths:
- '.github/workflows/protocol-publish.yml'
- 'libcockatrice_protocol/**'
workflow_dispatch:
inputs:
version:
description: 'Semver to publish (e.g. 15.0.0). Leave blank to dry-run only.'
required: false
default: ''
concurrency:
group: "${{ github.workflow }} @ ${{ github.ref_name }}"
cancel-in-progress: ${{ github.event_name != 'release' }}
jobs:
publish:
name: Build and publish protocol package
if: ${{ github.repository_owner == 'Cockatrice' }}
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://npm.pkg.github.com'
scope: '@cockatrice'
- name: Determine package version
id: pkgver
shell: bash
run: |
case "$GITHUB_EVENT_NAME" in
release)
version="${{ github.event.release.tag_name }}"
version="${version#v}"
publish=true
;;
workflow_dispatch)
version="${{ inputs.version }}"
if [[ -n "$version" ]]; then
version="${version#v}"
publish=true
else
version="0.0.0-manual"
publish=false
fi
;;
*) # pull_request
version="0.0.0-pr${{ github.event.pull_request.number }}"
publish=false
;;
esac
echo "version=$version" >>"$GITHUB_OUTPUT"
echo "publish=$publish" >>"$GITHUB_OUTPUT"
- name: Assemble package
shell: bash
env:
PKG_VERSION: ${{ steps.pkgver.outputs.version }}
run: |
pkg=build/protocol-package
rm -rf "$pkg"
mkdir -p "$pkg/pb"
cp libcockatrice_protocol/libcockatrice/protocol/pb/*.proto "$pkg/pb/"
cp libcockatrice_protocol/protocol_version.json "$pkg/"
cp libcockatrice_protocol/npm/package.json libcockatrice_protocol/npm/README.md "$pkg/"
cp LICENSE "$pkg/"
npm --prefix "$pkg" version --no-git-tag-version --allow-same-version "$PKG_VERSION"
- name: Pack and inspect (dry-run)
if: ${{ steps.pkgver.outputs.publish != 'true' }}
working-directory: build/protocol-package
run: |
npm pack
ls -la ./*.tgz
tar -tzf ./*.tgz | sort
- name: Publish to GitHub Packages
if: ${{ steps.pkgver.outputs.publish == 'true' }}
working-directory: build/protocol-package
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm publish