-
Notifications
You must be signed in to change notification settings - Fork 55
116 lines (101 loc) · 3.52 KB
/
deploy.yml
File metadata and controls
116 lines (101 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
name: Deploy
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: 'pages'
cancel-in-progress: false
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
verify-tag:
name: Verify Tag
runs-on: ubuntu-latest
outputs:
should_deploy: ${{ steps.check.outputs.should_deploy }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if tag is on main or master branch
id: check
run: |
git fetch origin main master || true
BRANCHES=$(git branch -r --contains ${{ github.ref }})
if echo "$BRANCHES" | grep -qE 'origin/(main|master)'; then
echo "✓ Tag is on main or master branch"
echo "should_deploy=true" >> $GITHUB_OUTPUT
else
echo "✗ Tag is not on main or master branch, skipping deployment"
echo "Tag is on: $BRANCHES"
echo "should_deploy=false" >> $GITHUB_OUTPUT
fi
- name: Verify version consistency
if: steps.check.outputs.should_deploy == 'true'
run: |
# Extract version from git tag (remove 'v' prefix)
TAG_VERSION="${{ github.ref_name }}"
TAG_VERSION="${TAG_VERSION#v}"
# Extract version from Cargo.toml
CARGO_VERSION=$(grep -m1 '^version' Cargo.toml | sed 's/.*"\(.*\)"/\1/')
echo "Git tag version: $TAG_VERSION"
echo "Cargo.toml version: $CARGO_VERSION"
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
echo "ERROR: Version mismatch! Tag version ($TAG_VERSION) != Cargo.toml version ($CARGO_VERSION)"
exit 1
fi
echo "✓ Version check passed!"
build:
name: Build documentation
runs-on: ubuntu-latest
needs: verify-tag
if: needs.verify-tag.outputs.should_deploy == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@nightly
- name: Build docs
env:
RUSTDOCFLAGS: -D rustdoc::broken_intra_doc_links -D missing-docs
run: |
# Build documentation
cargo doc --no-deps --all-features
# Auto-detect documentation directory
# Check if doc exists in target/doc or target/*/doc
if [ -d "target/doc" ]; then
DOC_DIR="target/doc"
else
# Find doc directory under target/*/doc pattern
DOC_DIR=$(find target -type d -name doc -path "target/*/doc" | head -n 1)
if [ -z "$DOC_DIR" ]; then
echo "Error: Could not find documentation directory"
exit 1
fi
fi
echo "Documentation found in: $DOC_DIR"
printf '<meta http-equiv="refresh" content="0;url=%s/index.html">' $(cargo tree | head -1 | cut -d' ' -f1) > "${DOC_DIR}/index.html"
echo "DOC_DIR=${DOC_DIR}" >> $GITHUB_ENV
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ${{ env.DOC_DIR }}
deploy:
name: Deploy to GitHub Pages
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: [verify-tag, build]
if: needs.verify-tag.outputs.should_deploy == 'true'
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4