obelisk 0.37.4

Deterministic workflow engine
name: push-js-runtime

permissions:
  contents: write

on:
  workflow_dispatch:
    inputs:
      runtime_type:
        description: "Which JS runtime to push"
        required: true
        type: choice
        options:
          - activity-js-runtime
          - workflow-js-runtime
          - webhook-js-runtime
      tag:
        description: "The tag to be used when pushing the runtime to Docker Hub."
        required: true
        type: string
      ref:
        description: "The ref (branch or SHA) to process"
        required: false
        type: string
      push_to_main:
        description: "Push directly to main instead of creating a PR"
        required: false
        type: boolean
        default: false

defaults:
  run:
    shell: bash -xe {0}

jobs:
  push-js-runtime:
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          ref: ${{ github.event.inputs.ref }}

      - uses: nixbuild/nix-quick-install-action@v34
        with:
          github_access_token: ${{ secrets.GITHUB_TOKEN }}
          nix_conf: |
            extra-substituters = https://cache.garnix.io
            extra-trusted-public-keys = cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g

      - name: Populate the nix store
        run: nix develop --command echo

      - name: Log in to Docker Hub
        run: |
          echo "$DOCKER_HUB_TOKEN" | docker login -u "$DOCKER_HUB_USERNAME" --password-stdin
        env:
          DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
          DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}

      - name: Push JS runtime
        run: |
          nix develop --command ./scripts/push-$RUNTIME_TYPE.sh $TAG
        env:
          RUNTIME_TYPE: ${{ github.event.inputs.runtime_type }}
          TAG: ${{ github.event.inputs.tag }}

      - name: Configure git before push
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"

      - name: Generate Unique Branch Name
        id: branch-name
        run: echo "branch_name=bump-$RUNTIME_TYPE-$(date +'%Y%m%d-%H%M%S')" >> $GITHUB_OUTPUT
        env:
          RUNTIME_TYPE: ${{ github.event.inputs.runtime_type }}

      - name: Push directly to main
        if: ${{ github.event.inputs.push_to_main == 'true' }}
        run: |
          git add .
          git commit -m "chore: Bump $RUNTIME_TYPE runtime to $TAG"
          git push origin main
        env:
          RUNTIME_TYPE: ${{ github.event.inputs.runtime_type }}
          TAG: ${{ github.event.inputs.tag }}

      - name: Create a PR
        if: ${{ github.event.inputs.push_to_main != 'true' }}
        run: |
          git checkout -b ${{ steps.branch-name.outputs.branch_name }}
          git add .
          git commit -m "chore: Bump $RUNTIME_TYPE runtime to $TAG"
          git push origin ${{ steps.branch-name.outputs.branch_name }}
          OWNER=$(echo "${{ github.repository }}" | cut -d'/' -f1)
          REPO=$(echo "${{ github.repository }}" | cut -d'/' -f2)
          curl -v --fail -X POST \
            -H "Content-Type: application/json" \
            -H "Authorization: Bearer $GITHUB_TOKEN" \
            https://api.github.com/repos/$OWNER/$REPO/pulls \
            -d '{
              "title": "chore: Bump '"$RUNTIME_TYPE"' runtime to '"$TAG"'",
              "head": "'${{ steps.branch-name.outputs.branch_name }}'",
              "base": "main",
              "body": ""
            }'
        env:
          RUNTIME_TYPE: ${{ github.event.inputs.runtime_type }}
          TAG: ${{ github.event.inputs.tag }}
          GITHUB_TOKEN: ${{ secrets.GH_TOKEN_PR_RW }}