-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce dedicated publish workflow
Introduce a dedicated workflow for publishing the crate by push of a button. This is a much nicer experience than having to push a tag, in my opinion, and there is no longer a need for mismatch check. Instead of the user having to create the tag, let GitHub Actions do it for us. Security-wise this reversal shouldn't matter: it's just meta-data attached to a commit, which we can easily verify that it hasn't changed. Because tags did not seem to be signed in past, we are not loosing anything there either by having a some piece of infrastructure do it. Signed-off-by: Daniel Müller <[email protected]>
- Loading branch information
1 parent
5f25d02
commit 1753345
Showing
2 changed files
with
64 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: Publish | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
version: | ||
name: Retrieve version | ||
runs-on: ubuntu-latest | ||
outputs: | ||
version: ${{ steps.version.outputs.version }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- id: version | ||
shell: bash | ||
run: | | ||
cargo generate-lockfile | ||
pkgid="$(cargo pkgid)" | ||
# Format is typically | ||
# file://<path>/<crate>#<version> | ||
# but could also be along the lines of | ||
# file://<path>/<crate>#<actual-crate-name>@<version> | ||
version="$(echo ${pkgid} | cut -d '#' -f2 | cut -d '@' -f2 | grep -o '[^:]*$')" | ||
if [ -z "${version}" ]; then | ||
echo "Invalid version string: ${pkgid}" | ||
exit 1 | ||
fi | ||
echo "Determined crate version: ${version}" | ||
echo "version=${version}" >> $GITHUB_OUTPUT | ||
test: | ||
uses: ./.github/workflows/ci.yml | ||
secrets: inherit | ||
publish: | ||
needs: [test, version] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: dtolnay/rust-toolchain@stable | ||
- name: Dry-run package creation | ||
run: cargo package --no-verify | ||
- name: Create git tag | ||
env: | ||
version: ${{ needs.version.outputs.version }} | ||
run: | | ||
curl --location \ | ||
--fail-with-body \ | ||
--request POST \ | ||
--url https://api.github.com/repos/${{ github.repository }}/releases \ | ||
--header "Accept: application/vnd.github+json" \ | ||
--header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | ||
--header "X-GitHub-Api-Version: 2022-11-28" \ | ||
--data "{ | ||
\"tag_name\":\"v${version}\", | ||
\"target_commitish\":\"${{ github.ref }}\", | ||
\"name\":\"v${version}\", | ||
\"draft\":false, | ||
\"prerelease\":false, | ||
\"generate_release_notes\":false | ||
}" | ||
- name: Publish | ||
run: cargo publish --no-verify --token "${CARGO_REGISTRY_TOKEN}" | ||
env: | ||
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |