From 6374fb00c0f5f1146480f540e00a03a2836cbfa1 Mon Sep 17 00:00:00 2001 From: Manuel Martinez Date: Tue, 5 Sep 2023 22:25:21 -0700 Subject: [PATCH 1/3] build: add github action for publishing crates --- .github/workflows/crates_upload.yml | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/crates_upload.yml diff --git a/.github/workflows/crates_upload.yml b/.github/workflows/crates_upload.yml new file mode 100644 index 000000000..a1d269bd5 --- /dev/null +++ b/.github/workflows/crates_upload.yml @@ -0,0 +1,43 @@ +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 + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Install stable toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + + - name: Publish libcst_derive to crates.io + uses: actions-rs/cargo@v1 + with: + command: publish + args: > + --manifest-path ./native/libcst_derive/Cargo.toml + --allow-dirty + --locked + --token ${{ secrets.CRATES_IO_TOKEN }} + + - name: Publish libsct to crates.io + uses: actions-rs/cargo@v1 + with: + command: publish + args: > + --manifest-path ./native/libcst/Cargo.toml + --allow-dirty + --locked + --token ${{ secrets.CRATES_IO_TOKEN }} From 2fe90b52a716c0e15c680f7f1887d9593510a82a Mon Sep 17 00:00:00 2001 From: Manuel Martinez Date: Thu, 21 Sep 2023 00:05:46 -0700 Subject: [PATCH 2/3] feat: use git tag and mirror pypi flow --- .github/workflows/crates_upload.yml | 38 ++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/.github/workflows/crates_upload.yml b/.github/workflows/crates_upload.yml index a1d269bd5..c5df7154b 100644 --- a/.github/workflows/crates_upload.yml +++ b/.github/workflows/crates_upload.yml @@ -13,6 +13,12 @@ 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 @@ -22,22 +28,46 @@ jobs: with: toolchain: stable - - name: Publish libcst_derive to crates.io + - name: Get version from Cargo.toml + id: get_cargo_version + run: > + echo + "CARGO_VERSION=$(grep -oP '(?<=^version = ").*(?="$)' + ./native/${{ matrix.package }}/Cargo.toml)" + >> $GITHUB_ENV + + - name: Get version from Git tag + id: get_git_version + run: > + echo + "GIT_VERSION=$(git describe --tags --abbrev=0 | tail -c +2)" + >> $GITHUB_ENV + + - name: Replace version + id: replace_version + run: > + sed -i "s/${CARGO_VERSION}/${GIT_VERSION}/g" + ./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/libcst_derive/Cargo.toml + --manifest-path ./native/${{ matrix.package }}/Cargo.toml --allow-dirty --locked + --dry-run --token ${{ secrets.CRATES_IO_TOKEN }} - - name: Publish libsct to crates.io + - name: Publish ${{ matrix.package }} to crates.io + if: github.event_name == 'release' uses: actions-rs/cargo@v1 with: command: publish args: > - --manifest-path ./native/libcst/Cargo.toml + --manifest-path ./native/${{ matrix.package }}/Cargo.toml --allow-dirty --locked --token ${{ secrets.CRATES_IO_TOKEN }} From f23af55a572161c438422a01f879708c1d57ff1f Mon Sep 17 00:00:00 2001 From: Manuel Martinez Date: Fri, 22 Sep 2023 22:43:21 -0700 Subject: [PATCH 3/3] feat: fetch version from git --- .github/workflows/crates_upload.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/crates_upload.yml b/.github/workflows/crates_upload.yml index c5df7154b..c70578e0c 100644 --- a/.github/workflows/crates_upload.yml +++ b/.github/workflows/crates_upload.yml @@ -19,34 +19,41 @@ jobs: 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 - id: get_cargo_version run: > echo - "CARGO_VERSION=$(grep -oP '(?<=^version = ").*(?="$)' + "CARGO_VERSION=$(grep -oP '(?<=^version = ")[^"]*' ./native/${{ matrix.package }}/Cargo.toml)" >> $GITHUB_ENV - name: Get version from Git tag - id: get_git_version run: > echo "GIT_VERSION=$(git describe --tags --abbrev=0 | tail -c +2)" >> $GITHUB_ENV - name: Replace version - id: replace_version run: > - sed -i "s/${CARGO_VERSION}/${GIT_VERSION}/g" + sed -i "0,/${CARGO_VERSION}/s//${GIT_VERSION}/" ./native/${{ matrix.package }}/Cargo.toml - name: Dry run publish ${{ matrix.package }} @@ -57,7 +64,6 @@ jobs: args: > --manifest-path ./native/${{ matrix.package }}/Cargo.toml --allow-dirty - --locked --dry-run --token ${{ secrets.CRATES_IO_TOKEN }}