name: Release
on:
push:
branches: [main]
permissions: {}
jobs:
release-please:
name: Release PR / tag
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release.outputs.release_created }}
steps:
- uses: actions/create-github-app-token@v2
id: app-token
with:
app-id: ${{ vars.RELEASE_APP_CLIENT_ID || secrets.RELEASE_APP_CLIENT_ID }}
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
- uses: googleapis/release-please-action@v4
id: release
with:
token: ${{ steps.app-token.outputs.token }}
config-file: release-please-config.json
manifest-file: .release-please-manifest.json
publish:
name: Publish to crates.io
needs: release-please
if: needs.release-please.outputs.release_created == 'true'
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write contents: read
steps:
- uses: actions/checkout@v4
- name: Check whether this version is already published
id: check
run: |
version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)"
echo "version=${version}"
if curl -fsS -H "user-agent: xisf-header release workflow (github.com/nightwatch-astro/xisf-header)" \
"https://crates.io/api/v1/crates/xisf-header/${version}" > /dev/null; then
echo "published=true" >> "$GITHUB_OUTPUT"
else
echo "published=false" >> "$GITHUB_OUTPUT"
fi
- uses: dtolnay/rust-toolchain@stable
if: steps.check.outputs.published == 'false'
- uses: rust-lang/crates-io-auth-action@v1
id: auth
if: steps.check.outputs.published == 'false'
- run: cargo publish
if: steps.check.outputs.published == 'false'
env:
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}