name: Publish to Cargo
on:
push:
branches: [ master ]
jobs:
publish:
runs-on: ubuntu-latest
name: 'publish'
environment: cargo
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: Generate a changelog
uses: orhun/git-cliff-action@v3
id: git-cliff
with:
config: cliff.toml
args: --verbose
env:
OUTPUT: CHANGELOG.md
- name: Print the changelog
run: cat "${{ steps.git-cliff.outputs.changelog }}"
- name: Commit
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
set +e
git add CHANGELOG.md
git commit -m "Update changelog"
git push https://${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git master
- name: Check if version is already published
id: check-version
run: |
PACKAGE_NAME="rust-jav"
CURRENT_VERSION=$(cargo pkgid | cut -d# -f2)
PUBLISHED_VERSIONS=$(cargo search $PACKAGE_NAME | grep "^$PACKAGE_NAME =" | cut -d'"' -f2)
if [[ "$PUBLISHED_VERSIONS" == *"$CURRENT_VERSION"* ]]; then
echo "Version $CURRENT_VERSION of $PACKAGE_NAME is already published."
echo "SKIP_PUBLISH=true" >> $GITHUB_ENV
else
echo "Version $CURRENT_VERSION of $PACKAGE_NAME is not published."
echo "SKIP_PUBLISH=false" >> $GITHUB_ENV
fi
- name: Login to crates.io
uses: actions-rs/cargo@v1
with:
command: login
args: ${{ secrets.CARGO_TOKEN }}
- name: Publish to crates.io
uses: actions-rs/cargo@v1
if: env.SKIP_PUBLISH == 'false'
with:
command: publish
args: --verbose --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_TOKEN }}