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 that exports everything from the subfolders # This makes 'import { PisMapping } from "@owlboard/backend-data-contracts"' work. find . -name "*.ts" | sed 's|^\./||; s|\.ts$||' | xargs -I {} echo "export * from './{}';" > index.ts # 2. Update package.json # We point main/types to the root dist/index file we are about to create 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 using the created index.ts as the entry point # tsc will automatically follow the imports in index.ts and find the nested files 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: | cd gen/go go mod init git.fjla.uk/owlboard/backend-data-contracts go mod tidy zip -r ../../rail-backend-${{ steps.get_version.outputs.VERSION }}.zip . curl --user "owlbot:${{ secrets.PACKAGE_PUSH }}" \ --upload-file ../../rail-backend-${{ steps.get_version.outputs.VERSION }}.zip \ https://${{ github.server_url }}/api/packages/owlboard/go/upload