Skip to content

Commit c8c99f6

Browse files
committed
ci: add release pipeline
1 parent 28bbc05 commit c8c99f6

5 files changed

Lines changed: 524 additions & 0 deletions

File tree

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: build-artifacts
2+
on:
3+
workflow_call:
4+
workflow_dispatch:
5+
6+
jobs:
7+
build-artifacts:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
contents: write
11+
env:
12+
BUILD_NAME: "flashy-${{ github.ref_name }}-linux-x64"
13+
DATABASE_URL: "sqlite:flashy.db"
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v6
18+
19+
- name: Install Rust toolchain
20+
uses: dtolnay/rust-toolchain@nightly
21+
22+
- name: Add WASM target
23+
run: rustup target add wasm32-unknown-unknown
24+
25+
- name: Install Node.js (for tailwind)
26+
uses: actions/setup-node@v6
27+
with:
28+
node-version: '24'
29+
30+
- name: Install Node.js dependencies
31+
run: npm install
32+
33+
- name: Install SQLx CLI
34+
run: |
35+
cargo install sqlx-cli --no-default-features --features sqlite
36+
37+
- name: Setup database for SQLx compile-time verification
38+
run: |
39+
sqlx database create
40+
sqlx migrate run
41+
42+
- name: Cache cargo registry and target
43+
uses: actions/cache@v5
44+
with:
45+
path: |
46+
~/.cargo/registry/index
47+
~/.cargo/registry/cache
48+
~/.cargo/git/db
49+
target
50+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
51+
restore-keys: |
52+
${{ runner.os }}-cargo-
53+
54+
- name: Install cargo-leptos
55+
run: |
56+
curl --proto '=https' --tlsv1.3 -LsSf \
57+
https://github.com/leptos-rs/cargo-leptos/releases/latest/download/cargo-leptos-installer.sh | sh
58+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
59+
60+
- name: Build release with cargo-leptos
61+
run: |
62+
cargo leptos build --release
63+
64+
- name: Bundle release
65+
shell: bash
66+
run: |
67+
mkdir -p "$BUILD_NAME"
68+
69+
# Copy documentation
70+
cp README.md LICENSE "$BUILD_NAME/" || true
71+
72+
# Copy server binary
73+
cp "target/release/flashy" "$BUILD_NAME/"
74+
chmod +x "$BUILD_NAME/flashy"
75+
76+
# Copy site directory (WASM, JS, CSS, assets)
77+
cp -r target/site "$BUILD_NAME/"
78+
79+
# Copy migrations for database setup
80+
cp -r migrations "$BUILD_NAME/"
81+
82+
# Create a simple run script
83+
cat > "$BUILD_NAME/run.sh" << 'EOF'
84+
#!/bin/bash
85+
set -e
86+
87+
# Set environment variables
88+
export LEPTOS_SITE_ROOT="./site"
89+
export DATABASE_URL="${DATABASE_URL:-sqlite:flashy.db}"
90+
export RUST_LOG="${RUST_LOG:-info}"
91+
export LEPTOS_SITE_ADDR="${LEPTOS_SITE_ADDR:-127.0.0.1:8080}"
92+
93+
echo "Starting Flashy App..."
94+
echo "Site root: $LEPTOS_SITE_ROOT"
95+
echo "Database: $DATABASE_URL"
96+
echo "Listening on: $LEPTOS_SITE_ADDR"
97+
98+
# Run the server
99+
./flashy
100+
EOF
101+
102+
chmod +x "$BUILD_NAME/run.sh"
103+
104+
- name: Create tarball
105+
shell: bash
106+
run: |
107+
tar -czf "$BUILD_NAME.tar.gz" "$BUILD_NAME"
108+
109+
- name: Upload artifact
110+
uses: actions/upload-artifact@v7
111+
with:
112+
name: ${{ env.BUILD_NAME }}
113+
path: ${{ env.BUILD_NAME }}.tar.gz
114+
if-no-files-found: error

.github/workflows/ci.yml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
6+
env:
7+
CARGO_TERM_COLOR: always
8+
RUST_BACKTRACE: 1
9+
DATABASE_URL: sqlite:flashy.db
10+
11+
jobs:
12+
lint:
13+
name: Format & Lint
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v6
17+
18+
- name: Install Rust toolchain
19+
uses: dtolnay/rust-toolchain@nightly
20+
with:
21+
components: rustfmt, clippy
22+
targets: wasm32-unknown-unknown
23+
24+
- name: Setup Rust cache
25+
uses: Swatinem/rust-cache@v2
26+
with:
27+
cache-on-failure: true
28+
29+
- name: Check formatting
30+
run: cargo fmt --all -- --check
31+
32+
- name: Install SQLx CLI
33+
run: cargo install sqlx-cli --no-default-features --features sqlite --locked
34+
env:
35+
CARGO_TARGET_DIR: /tmp/sqlx-build
36+
37+
- name: Create database and run migrations
38+
run: |
39+
sqlx database create
40+
sqlx migrate run
41+
42+
- name: Run Clippy
43+
run: cargo clippy --all-targets --all-features -- -D warnings
44+
45+
test:
46+
name: Test Suite
47+
runs-on: ubuntu-latest
48+
steps:
49+
- uses: actions/checkout@v6
50+
51+
- name: Install Rust toolchain
52+
uses: dtolnay/rust-toolchain@nightly
53+
with:
54+
targets: wasm32-unknown-unknown
55+
56+
- name: Setup Rust cache
57+
uses: Swatinem/rust-cache@v2
58+
with:
59+
cache-on-failure: true
60+
61+
- name: Install SQLx CLI
62+
run: cargo install sqlx-cli --no-default-features --features sqlite --locked
63+
env:
64+
CARGO_TARGET_DIR: /tmp/sqlx-build
65+
66+
- name: Create database and run migrations
67+
run: |
68+
sqlx database create
69+
sqlx migrate run
70+
71+
- name: Run tests
72+
run: cargo test --all-features
73+
74+
build:
75+
name: Build (Leptos SSR)
76+
runs-on: ubuntu-latest
77+
steps:
78+
- uses: actions/checkout@v6
79+
80+
- name: Install Rust toolchain
81+
uses: dtolnay/rust-toolchain@nightly
82+
with:
83+
targets: wasm32-unknown-unknown
84+
85+
- name: Setup Rust cache
86+
uses: Swatinem/rust-cache@v2
87+
with:
88+
cache-on-failure: true
89+
90+
- name: Install cargo-leptos
91+
run: cargo install cargo-leptos --locked
92+
93+
- name: Install SQLx CLI
94+
run: cargo install sqlx-cli --no-default-features --features sqlite --locked
95+
env:
96+
CARGO_TARGET_DIR: /tmp/sqlx-build
97+
98+
- name: Create database and run migrations
99+
run: |
100+
sqlx database create
101+
sqlx migrate run
102+
103+
- name: Build with cargo-leptos
104+
run: cargo leptos build --release
105+
106+
- name: Upload build artifacts
107+
uses: actions/upload-artifact@v7
108+
with:
109+
name: leptos-build
110+
path: |
111+
target/release/flashy
112+
target/site/
113+
retention-days: 3
114+
115+
security-audit:
116+
name: Security Audit
117+
runs-on: ubuntu-latest
118+
steps:
119+
- uses: actions/checkout@v6
120+
121+
- name: Install Rust toolchain
122+
uses: dtolnay/rust-toolchain@nightly
123+
124+
- name: Setup Rust cache
125+
uses: Swatinem/rust-cache@v2
126+
with:
127+
cache-on-failure: true
128+
129+
- name: Install cargo-audit
130+
run: cargo install cargo-audit --locked
131+
132+
- name: Run security audit
133+
run: cargo audit
134+
135+
all-checks-passed:
136+
name: All Checks Passed
137+
runs-on: ubuntu-latest
138+
needs: [lint, test, build, security-audit]
139+
if: always()
140+
steps:
141+
- name: Check if all jobs passed
142+
run: |
143+
if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then
144+
echo "One or more checks failed"
145+
exit 1
146+
fi
147+
echo "All checks passed successfully!"
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: Create Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Release Version (e.g. v0.2.0)'
8+
required: true
9+
type: string
10+
11+
jobs:
12+
validate-version:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Validate version format
16+
run: |
17+
if [[ ! "${{ inputs.version }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
18+
echo "Error: Version must be in format vX.Y.Z (e.g., v0.2.0)"
19+
exit 1
20+
fi
21+
echo "Version format is valid: ${{ inputs.version }}"
22+
23+
bump-and-tag:
24+
needs: [validate-version]
25+
runs-on: ubuntu-latest
26+
permissions:
27+
contents: write
28+
steps:
29+
- uses: actions/checkout@v6
30+
with:
31+
token: ${{ secrets.GH_PAT }}
32+
33+
- uses: dtolnay/rust-toolchain@stable
34+
35+
- name: Get current month for cache key
36+
id: month
37+
run: echo "month=$(date +%Y-%m)" >> $GITHUB_OUTPUT
38+
39+
- name: Cache cargo-edit
40+
id: cache-cargo-edit
41+
uses: actions/cache@v5
42+
with:
43+
path: |
44+
~/.cargo/bin/cargo-set-version
45+
~/.cargo/bin/cargo-add
46+
~/.cargo/bin/cargo-rm
47+
~/.cargo/bin/cargo-upgrade
48+
key: ${{ runner.os }}-cargo-edit-${{ steps.month.outputs.month }}
49+
50+
- name: Install cargo-edit
51+
if: steps.cache-cargo-edit.outputs.cache-hit != 'true'
52+
run: cargo install cargo-edit
53+
54+
- name: Bump version in Cargo.toml
55+
run: |
56+
CLEAN_VERSION=$(echo "${{ inputs.version }}" | sed 's/^v//')
57+
echo "Updating version to $CLEAN_VERSION"
58+
cargo set-version "$CLEAN_VERSION"
59+
60+
- name: Verify version was updated
61+
run: |
62+
CARGO_VERSION=$(grep '^version = ' Cargo.toml | head -1 | cut -d'"' -f2)
63+
EXPECTED_VERSION=$(echo "${{ inputs.version }}" | sed 's/^v//')
64+
65+
if [ "$CARGO_VERSION" != "$EXPECTED_VERSION" ]; then
66+
echo "Error: Version mismatch. Expected $EXPECTED_VERSION but got $CARGO_VERSION"
67+
exit 1
68+
fi
69+
70+
echo "Version successfully updated to $CARGO_VERSION"
71+
72+
- name: Commit and tag
73+
run: |
74+
CLEAN_VERSION=$(echo "${{ inputs.version }}" | sed 's/^v//')
75+
76+
git config --global user.name "github-actions[bot]"
77+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
78+
79+
git add Cargo.toml Cargo.lock
80+
git commit -m "chore: release v$CLEAN_VERSION [no ci]"
81+
82+
git tag "${{ inputs.version }}"
83+
84+
git push
85+
git push origin "${{ inputs.version }}"
86+
87+
echo "## Version Bump Complete" >> $GITHUB_STEP_SUMMARY
88+
echo "" >> $GITHUB_STEP_SUMMARY
89+
echo "- **Version**: ${{ inputs.version }}" >> $GITHUB_STEP_SUMMARY
90+
echo "- **Commit**: $(git rev-parse HEAD)" >> $GITHUB_STEP_SUMMARY
91+
echo "- **Tag**: ${{ inputs.version }}" >> $GITHUB_STEP_SUMMARY
92+
93+
- name: Create GitHub Release
94+
env:
95+
GH_TOKEN: ${{ secrets.GH_PAT }}
96+
run: |
97+
gh release create "${{ inputs.version }}" \
98+
--draft=false \
99+
--latest \
100+
--generate-notes \
101+
--title "Release ${{ inputs.version }}" \
102+
--notes "This release was automatically created by GitHub Actions.
103+
104+
## Installation
105+
106+
### Docker Compose
107+
108+
Download the \`docker-compose.yml\` and the \`.env.example\`, rename it to \`.env\`, create a \`data\` directory and start it.
109+
110+
\`\`\`bash
111+
docker compose up -d
112+
\`\`\`
113+
114+
### Docker
115+
116+
\`\`\`bash
117+
docker pull ghcr.io/${{ github.repository }}:${{ inputs.version }}
118+
docker run -p 8080:8080 -v ./data:/app/data ghcr.io/${{ github.repository }}:${{ inputs.version }}
119+
\`\`\`
120+
121+
### Binary
122+
123+
Download the binary assets below, extract it, and run:
124+
\`\`\`bash
125+
./run.sh
126+
\`\`\`"

0 commit comments

Comments
 (0)