name: Publish sctrace

on:
  workflow_dispatch:
  pull_request:
    paths:
      - VERSION
      - tools/sctrace/**
  push:
    branches:
      - main
    paths:
      - VERSION

jobs:
  publish:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    container: asterinas/asterinas:0.17.2-20260407
    steps:
      - uses: actions/checkout@v4

      - name: Publish sctrace (dry run)
        # On pull request, set `--dry-run` to check whether they can be published
        if: github.event_name == 'pull_request'
        run: |
          ./tools/github_workflows/publish_sctrace.sh --dry-run

      - name: Publish sctrace
        if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
        env:
          REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: |
          ./tools/github_workflows/publish_sctrace.sh --token ${REGISTRY_TOKEN}
