Add publish workflow
This commit is contained in:
parent
e525427f3e
commit
2b110af845
1 changed files with 67 additions and 0 deletions
67
.forgejo/workflows/publish.yml
Normal file
67
.forgejo/workflows/publish.yml
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
name: Publish Cargo Package
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: docker
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
CARGO_REGISTRIES_FORGEJO_TOKEN: Bearer ${{ secrets.FORGEJO_CARGO_TOKEN }}
|
||||
FORGEJO_CARGO_INDEX: ${{ github.server_url }}/${{ github.repository_owner }}/_cargo-index.git
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: https://data.forgejo.org/actions/checkout@v4
|
||||
|
||||
- name: Install Rust
|
||||
run: |
|
||||
if ! command -v cargo >/dev/null 2>&1; then
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
|
||||
fi
|
||||
|
||||
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
|
||||
. "$HOME/.cargo/env"
|
||||
rustup toolchain install stable --profile minimal
|
||||
rustup default stable
|
||||
cargo --version
|
||||
|
||||
- name: Configure Cargo registry
|
||||
run: |
|
||||
mkdir -p "$HOME/.cargo"
|
||||
cat > "$HOME/.cargo/config.toml" <<EOF
|
||||
[registries.forgejo]
|
||||
index = "${FORGEJO_CARGO_INDEX}"
|
||||
|
||||
[net]
|
||||
git-fetch-with-cli = true
|
||||
EOF
|
||||
|
||||
- name: Verify tag matches package version
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
run: |
|
||||
version=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)
|
||||
tag="${GITHUB_REF_NAME#v}"
|
||||
|
||||
if [ -z "$version" ]; then
|
||||
echo "Could not determine package version from Cargo.toml"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$version" != "$tag" ]; then
|
||||
echo "Tag version ($tag) does not match Cargo.toml version ($version)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Check package can be published
|
||||
run: |
|
||||
. "$HOME/.cargo/env"
|
||||
cargo publish --dry-run --locked --registry forgejo
|
||||
|
||||
- name: Publish package
|
||||
run: |
|
||||
. "$HOME/.cargo/env"
|
||||
cargo publish --locked --registry forgejo
|
||||
Loading…
Add table
Add a link
Reference in a new issue