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

CI: fix the github action that publishes the cargo docs #3645

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
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
44 changes: 5 additions & 39 deletions .github/workflows/cargo-doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,8 @@ jobs:

steps:
- uses: actions/checkout@v3

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

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

- name: Generate docs
run: cargo doc --workspace

- name: Move docs to gh-pages branch
run: |
mkdir -p /tmp/cargo-doc-output
mv target/doc /tmp/cargo-doc-output/doc

- uses: actions/checkout@v3
with:
ref: gh-pages

- name: Replace old docs with new docs
run: |
rm -rf ./doc
mv /tmp/cargo-doc-output/doc doc

- name: Commit and push new docs
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: cargo docs for ${{ env.GITHUB_SHA }}
branch: gh-pages
commit_user_name: prisma-bot
commit_user_email: [email protected]
commit_author: prisma-bot <[email protected]>

- uses: cachix/install-nix-action@v18
- run: |
git config user.email "[email protected]"
git config user.name "prisma-bot"
- run: nix run .#publish-cargo-docs
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
imports = [
./nix/all-engines.nix
./nix/args.nix
./nix/cargo-doc.nix
./nix/cli-shell.nix
./nix/dev-vm.nix
./nix/prisma-fmt-wasm.nix
Expand Down
50 changes: 50 additions & 0 deletions nix/cargo-doc.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{ pkgs, self', ... }:

{
packages.cargo-docs = pkgs.clangStdenv.mkDerivation {
name = "prisma-engines-cargo-docs";
inherit (self'.packages.prisma-engines) buildInputs nativeBuildInputs src;

buildPhase = ''
mkdir .cargo
ln -s ${self'.packages.prisma-engines-deps}/config.toml .cargo/config.toml
cargo doc --workspace
'';

installPhase = ''
mkdir -p $out/share
mv target/doc/ $out/share/docs
'';
};

packages.publish-cargo-docs = pkgs.writeShellApplication {
name = "publish-cargo-docs";
text = ''
set -euxo pipefail

if ! git diff --exit-code 1> /dev/null; then
: "The workspace is not clean. Please commit or reset, then try again".
exit 1
fi

CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
CURRENT_COMMIT=$(git rev-parse --short HEAD)
REPO_ROOT=$(git rev-parse --show-toplevel)

pushd "$REPO_ROOT"
git fetch --depth=1 origin gh-pages
git checkout origin/gh-pages
rm -rf ./doc
cp \
--recursive \
--no-preserve=mode,ownership \
${self'.packages.cargo-docs}/share/docs \
./doc
git add doc
git commit --quiet -m "cargo docs for $CURRENT_COMMIT"
git push origin '+HEAD:gh-pages'
git checkout "$CURRENT_BRANCH"
popd
'';
};
}