name: Generate and Release Protos on: push: tags: - 'v*' jobs: release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 with: fetch-depth: 0 persist-credentials: false - name: Get Version id: get_version run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT - uses: bufbuild/buf-action@v1.3 with: setup_only: true version: '1.63.0' - uses: actions/setup-go@v5 with: go-version: '1.23' - uses: actions/setup-node@v6 with: node-version: '18.18.x' registry-url: 'https://git.fjla.uk/api/packages/owlboard/npm' scope: '@owlboard' - name: Install Go Protoc Plugin run: | go install google.golang.org/protobuf/cmd/protoc-gen-go@latest echo "$(go env GOPATH)/bin" >> $GITHUB_PATH - name: Install TS-Proto Plugin run: | npm install ts-proto typescript echo "$PATH:$(pwd)/ts-proto" >> $GITHUB_PATH - name: Generate Code run: buf generate - name: Build and Publish TS working-directory: gen/ts run: | npm init -y # 1. Create a dynamic index.ts using Namespace exports # This converts 'rail_backend/v1/pis_mapping.ts' # into 'export * as PisMapping from "./rail_backend/v1/pis_mapping";' # We use awk to handle the naming conversion (snake_case to PascalCase-ish) find . -name "*.ts" -not -name "index.ts" | sed 's|^\./||; s|\.ts$||' | awk -F'/' '{ name=$NF; gsub(/_/, "", name); printf "export * as %s from \"./%s\";\n", toupper(substr(name,1,1)) substr(name,2), $0 }' > index.ts # 2. Update package.json jq '.name = "@owlboard/backend-data-contracts" | .version = "${{ steps.get_version.outputs.VERSION }}" | .type = "module" | .main = "./dist/index.js" | .types = "./dist/index.d.ts" | .publishConfig = { "registry": "https://git.fjla.uk/api/packages/owlboard/npm" }' \ package.json > temp.json && mv temp.json package.json # 3. Compile npx tsc index.ts --declaration --module esnext --target es2022 --moduleResolution node --outDir dist/ npm publish env: NODE_AUTH_TOKEN: ${{ secrets.PACKAGE_PUSH }} - name: Publish Go run: | # 1. Setup variables VERSION="${{ steps.get_version.outputs.VERSION }}" MOD_NAME="git.fjla.uk/owlboard/backend-data-contracts" # Create a temporary directory structure that matches Go proxy requirements DEST_DIR="temp_zip/$MOD_NAME@$VERSION" # 2. Generate go.mod and tidy cd gen/go go mod init $MOD_NAME go mod tidy # 3. Move files into the required nested structure mkdir -p "../../$DEST_DIR" cp -r . "../../$DEST_DIR/" # 4. Zip from the temp root so the internal paths are correct cd ../../temp_zip zip -r ../module.zip . # 5. Upload with the explicit version cd .. curl -f -v --user "owlbot:${{ secrets.PACKAGE_PUSH }}" \ --upload-file module.zip \ "${{ github.server_url }}/api/packages/owlboard/go/upload?version=$VERSION"