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: actions/setup-go@v5 with: go-version: '1.24' - 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 Generators run: | npm install -g json-schema-to-typescript typescript go install github.com/atombender/go-jsonschema@latest echo "$(go env GOPATH)/bin" >> $GITHUB_PATH - run: bash scripts/build.sh - name: Build and Publish TS working-directory: gen/ts run: | npm init -y # Build index.ts echo "// Auto-generated" > index.ts find . -maxdepth 1 -name "*.ts" -not -name "index.ts" | sed 's|^\./||; s|\.ts$||' | awk '{ # Use gsub to turn hyphens into underscores so we can split easily clean = $0; gsub(/-/, "_", clean); n = split(clean, parts, "_"); name = ""; for (i=1; i<=n; i++) { if (length(parts[i]) > 0) { name = name toupper(substr(parts[i],1,1)) substr(parts[i],2); } } # name will now be 'DataIngressPisData' (valid TS) printf "export * as %s from \"./%s.js\";\n", name, $0 }' >> index.ts VERSION="${{ steps.get_version.outputs.VERSION }}" jq --arg ver "$VERSION" \ --arg name "@owlboard/backend-data-contracts" \ '.name = $name | .version = $ver | .type = "module" | .main = "./dist/index.js" | .types = "./dist/index.d.ts"' \ package.json > package.json.new && mv package.json.new package.json # Compile npx tsc index.ts --declaration --module nodenext --target es2022 --moduleResolution nodenext --outDir dist/ --skipLibCheck true # Publish npm config set //git.fjla.uk/api/packages/owlboard/npm/:_authToken ${{ secrets.PACKAGE_PUSH }} npm publish - name: Publish Go run: | # 1. Setup variables VERSION="v${{ 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"