name: Cargo
on:
workflow_dispatch:
jobs:
Checkout:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.read.outputs.version }}
should_trigger: ${{ steps.check_release.outputs.should_trigger }}
steps:
- uses: actions/checkout@v4
- name: Read Cargo.toml Version
id: read
run: |
VERSION=$(grep -m1 '^version' Cargo.toml | sed 's/version = "\(.*\)"/\1/')
echo "Version: $VERSION"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Check if Release Exists
id: check_release
run: |
RELEASE_URL="https://github.com/canmi21/openjlc/releases/tag/v${{ steps.read.outputs.version }}"
HTTP_STATUS=$(curl -o /dev/null -s -w "%{http_code}" "$RELEASE_URL")
if [ "$HTTP_STATUS" -eq 404 ]; then
echo "Release not found, triggering CI."
echo "should_trigger=true" >> "$GITHUB_OUTPUT"
else
echo "Release already exists, skipping CI."
echo "should_trigger=false" >> "$GITHUB_OUTPUT"
fi
- name: Trigger Rust CI
if: steps.check_release.outputs.should_trigger == 'true'
uses: actions/github-script@v7
with:
script: |
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'rust-ci.yml',
ref: context.ref.replace('refs/heads/', '')
});