Skip to content

Commit

Permalink
Update publish.yml
Browse files Browse the repository at this point in the history
Sanity check env
  • Loading branch information
mdr0id authored Sep 30, 2024
1 parent ed122c4 commit f200477
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,30 @@ jobs:
toolchain: stable
override: true

- name: Debug Token
env:
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: |
if [ -n "$CRATES_IO_TOKEN" ]; then
echo "CRATES_IO_TOKEN is set"
echo "CRATES_IO_TOKEN length: ${#CRATES_IO_TOKEN}"
else
echo "CRATES_IO_TOKEN is not set"
fi
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: |
if [ -z "$CARGO_REGISTRY_TOKEN" ]; then
echo "CARGO_REGISTRY_TOKEN is not set. Cannot publish."
exit 1
fi
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
# If it's a tag, publish as is
cargo publish
cargo publish --token ${CARGO_REGISTRY_TOKEN} || cargo publish --token ${CARGO_REGISTRY_TOKEN} --verbose
elif [[ "${{ github.ref }}" == refs/heads/master ]]; then
# If it's a push to master, publish as a pre-release version
VERSION=$(grep '^version =' Cargo.toml | sed -E 's/version = "(.*?)"/\1/')
COMMIT_HASH=$(git rev-parse --short HEAD)
NEW_VERSION="${VERSION}-pre.${COMMIT_HASH}"
sed -i "s/^version = \".*\"/version = \"${NEW_VERSION}\"/" Cargo.toml
CARGO_REGISTRY_TOKEN=${{ secrets.CRATES_IO_TOKEN }} cargo publish --allow-dirty
cargo publish --token ${CARGO_REGISTRY_TOKEN} --allow-dirty || cargo publish --token ${CARGO_REGISTRY_TOKEN} --allow-dirty --verbose
else
echo "Not publishing: not a push to master or a tag"
fi

0 comments on commit f200477

Please sign in to comment.