name: Publish OSDK

on:
  pull_request:
    paths:
      - VERSION
      - osdk/Cargo.toml
  push:
    branches:
      - main
    paths: 
      - VERSION

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

      - name: Check Publish
        # On pull request, set `--dry-run` to check whether OSDK can publish
        if: github.event_name == 'pull_request'
        run: |
          cd osdk
          cargo publish --dry-run
        
      - name: Publish
        # On push, OSDK will be published
        if: github.event_name == 'push'
        env:
          REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: |
          cd osdk
          cargo publish --token ${REGISTRY_TOKEN}
