Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: add github action for publishing crates #1012

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/workflows/crates_upload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: crates_upload

on:
release:
types: [published]
push:
branches: [main]

permissions:
contents: read

jobs:
upload_release:
name: Upload release to crates.io
runs-on: ubuntu-latest

strategy:
matrix:
package:
- libcst_derive
- libcst

steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Cache Cargo registry
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable

- name: Get version from Cargo.toml
run: >
echo
"CARGO_VERSION=$(grep -oP '(?<=^version = ")[^"]*'
./native/${{ matrix.package }}/Cargo.toml)"
>> $GITHUB_ENV

- name: Get version from Git tag
run: >
echo
"GIT_VERSION=$(git describe --tags --abbrev=0 | tail -c +2)"
>> $GITHUB_ENV

- name: Replace version
run: >
sed -i "0,/${CARGO_VERSION}/s//${GIT_VERSION}/"
./native/${{ matrix.package }}/Cargo.toml

- name: Dry run publish ${{ matrix.package }}
if: github.event_name == 'push'
uses: actions-rs/cargo@v1
with:
command: publish
args: >
--manifest-path ./native/${{ matrix.package }}/Cargo.toml
--allow-dirty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why --allow-dirty?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was testing locally with nektos/act and was getting an issue where cargo publish wouldn't allow files that weren't committed, even though the files were actually committed. Not sure if this would be the case on GitHub

--dry-run
--token ${{ secrets.CRATES_IO_TOKEN }}

- name: Publish ${{ matrix.package }} to crates.io
if: github.event_name == 'release'
uses: actions-rs/cargo@v1
with:
command: publish
args: >
--manifest-path ./native/${{ matrix.package }}/Cargo.toml
--allow-dirty
--locked
--token ${{ secrets.CRATES_IO_TOKEN }}