diff --git a/.github/read-template-registry/action.yaml b/.github/read-template-registry/action.yaml index 6bdc089..8d98e30 100644 --- a/.github/read-template-registry/action.yaml +++ b/.github/read-template-registry/action.yaml @@ -32,11 +32,13 @@ runs: TEMPLATE_DIR: ${{ inputs.template_dir }} run: | echo "name=$(jq -r '.name' "$TEMPLATE_DIR/registry.json")" >> "$GITHUB_OUTPUT" - echo "template_id=$(jq -r '.template_id' "$TEMPLATE_DIR/registry.json")" >> "$GITHUB_OUTPUT" + echo "template_id=$(jq -r '.template_id // empty' "$TEMPLATE_DIR/registry.json")" >> "$GITHUB_OUTPUT" echo "descr=$(jq -r '.description' "$TEMPLATE_DIR/registry.json")" >> "$GITHUB_OUTPUT" echo "params=$(jq -c '.params' "$TEMPLATE_DIR/registry.json")" >> "$GITHUB_OUTPUT" - { - echo 'instructions<> "$GITHUB_OUTPUT" + if [ -f "$TEMPLATE_DIR/instructions.md" ]; then + { + echo 'instructions<> "$GITHUB_OUTPUT" + fi diff --git a/.github/workflows/_publish_js.yml b/.github/workflows/_publish_js.yml new file mode 100644 index 0000000..9453cfd --- /dev/null +++ b/.github/workflows/_publish_js.yml @@ -0,0 +1,93 @@ +name: Publish JS template + +# Reusable workflow: build one TypeScript app to wasm via fastedge-build and +# publish it as a portal template. No Harbor/compiler image needed — the build +# toolchain comes from npm. Callers pass the workspace root, the per-app build +# command, and the resulting wasm path. + +on: + workflow_call: + inputs: + template: + description: Template name (job label) + required: true + type: string + working_directory: + description: Workspace root to run pnpm install in + required: true + type: string + build_command: + description: "Command that builds the wasm (e.g. pnpm -C otp-app build)" + required: true + type: string + output_path: + description: Built wasm destination (relative to repo root) + required: true + type: string + registry_dir: + description: Dir holding registry.json / instructions.md + required: true + type: string + +permissions: + contents: read + +jobs: + build_and_publish: + name: Build and publish ${{ inputs.template }} + runs-on: [self-hosted, ubuntu-22-04, regular] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Import credentials from Vault + uses: hashicorp/vault-action@v3 + id: creds + with: + url: https://puppet-vault.gc.onl + token: ${{ secrets.VAULT_TOKEN }} + secrets: | + secret/project_fastedge/gcore_api/preprod apitoken | PREPROD_API_KEY ; + secret/project_fastedge/gcore_api/preprod hostname | PREPROD_API_URL ; + secret/project_fastedge/gcore_api/prod apitoken | PROD_API_KEY ; + secret/project_fastedge/gcore_api/prod hostname | PROD_API_URL ; + + - name: Setup Node.js and install dependencies + uses: ./.github/setup-node + with: + working_directory: ${{ inputs.working_directory }} + + - name: Build ${{ inputs.template }} + working-directory: ${{ inputs.working_directory }} + run: ${{ inputs.build_command }} + + - name: Read ${{ inputs.template }} registry + id: registry + uses: ./.github/read-template-registry + with: + template_dir: ${{ inputs.registry_dir }} + + - name: Deploy ${{ inputs.template }} to preprod + uses: gcore-github-actions/fastedge/deploy-template@v1 + with: + api_key: ${{ steps.creds.outputs.PREPROD_API_KEY }} + api_url: ${{ steps.creds.outputs.PREPROD_API_URL }} + wasm_file: ${{ inputs.output_path }} + template_name: ${{ steps.registry.outputs.name }} + short_descr: ${{ steps.registry.outputs.descr }} + long_descr: ${{ steps.registry.outputs.instructions }} + params: ${{ steps.registry.outputs.params }} + + - name: Deploy ${{ inputs.template }} to prod + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + uses: gcore-github-actions/fastedge/deploy-template@v1 + with: + api_key: ${{ steps.creds.outputs.PROD_API_KEY }} + api_url: ${{ steps.creds.outputs.PROD_API_URL }} + wasm_file: ${{ inputs.output_path }} + template_name: ${{ steps.registry.outputs.name }} + template_id: ${{ steps.registry.outputs.template_id }} + short_descr: ${{ steps.registry.outputs.descr }} + long_descr: ${{ steps.registry.outputs.instructions }} + params: ${{ steps.registry.outputs.params }} diff --git a/.github/workflows/_publish.yml b/.github/workflows/_publish_rs.yml similarity index 62% rename from .github/workflows/_publish.yml rename to .github/workflows/_publish_rs.yml index 0b7286c..6d267b3 100644 --- a/.github/workflows/_publish.yml +++ b/.github/workflows/_publish_rs.yml @@ -1,12 +1,37 @@ -name: Publish template +name: Publish Rust template + +# Reusable workflow: build one Rust cdylib to wasm and publish it as a portal +# template. Simple templates (one dir = one package = one wasm) call this with +# just `template:`. Templates whose layout doesn't follow that convention +# (e.g. edge-sso filters living in a shared Cargo workspace) pass explicit +# paths to override the defaults. on: workflow_call: inputs: template: - description: Template directory / package name to build and publish + description: Template name (job label + default for the paths below) required: true type: string + rust_package: + description: "Cargo package name (default: template)" + required: false + type: string + working_directory: + description: "Dir containing the Cargo project (default: template)" + required: false + type: string + output_path: + description: "Built wasm destination (default: