From fd9cde3d437c8f3fc42fd9fe59d4ba89636d68f5 Mon Sep 17 00:00:00 2001 From: Maksym Pavlenko Date: Thu, 24 Aug 2023 13:36:37 -0700 Subject: [PATCH] Automate crates publishing Signed-off-by: Maksym Pavlenko --- .github/workflows/publish.yml | 64 +++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..9f1a9e3 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,64 @@ + # Automates crate publishing + # - Submit a PR to bump crate version. + # - Specify crate to publish from the menu. + # - Launch the job: + # + The job will extract version from Cargo.toml + # + Will publish to crates.io + # + Will add and push a git tag "-v" + +name: Release +on: + workflow_dispatch: + inputs: + crate: + description: 'Crate to publish' + required: true + type: choice + options: + - client + - logging + - runc + - runc-shim + - shim + - shim-protos + - snapshots + + dryrun: + description: 'Dry run' + required: false + type: boolean + default: false + +jobs: + publish: + name: 'Publish ${{ inputs.crate }}' + runs-on: ubuntu-latest + timeout-minutes: 10 + + permissions: + contents: write + + env: + CARGO_FILE: "crates/${{ inputs.crate }}/Cargo.toml" + + steps: + - uses: actions/checkout@v3 + + - name: Extract package version + id: extract_version + run: echo "version=${cargo pkgid --manifest-path $CARGO_FILE | sed 's/.*@//'}" >> $GITHUB_OUTPUT + + - name: Publish on crates.io + run: cargo publish $DRYRUN --manifest-path $CARGO_FILE + env: + DRYRUN: ${{ inputs.dryrun && '--dry-run' }} + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + + - name: Push version tag + if: ${{ !inputs.dryrun }} + env: + TAG: "${{ inputs.crate }}-v${{ steps.extract_version.outputs.version }}" + run: | + git tag $TAG + git push origin $TAG +