Skip to content

Commit

Permalink
DOC: Issue-118 - Added build and deployment process of homepage to a …
Browse files Browse the repository at this point in the history
…GitHub actions based workflow, with no need to handle a new branch and push changes to it.
  • Loading branch information
mtwardawski authored and mbfm committed Apr 12, 2024
1 parent d65c11e commit 9382be2
Show file tree
Hide file tree
Showing 9 changed files with 16,549 additions and 9 deletions.
70 changes: 61 additions & 9 deletions .ci/xtask/src/tasks/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ enum DocKindCli {
#[command(subcommand)]
task: BookCli,
},
/// Build and pack homepage for openDuT
Homepage {
#[command(subcommand)]
task: HomepageCli,
},
}
#[derive(Debug, clap::Subcommand)]
enum BookCli {
Expand All @@ -27,13 +32,22 @@ enum BookCli {
Open,
}

#[derive(Debug, clap::Subcommand)]
enum HomepageCli {
/// Build the homepage
Build,
}

impl DocCli {
pub fn default_handling(&self) -> crate::Result {
match &self.kind {
DocKindCli::Book { task } => match task {
BookCli::Build => book::build()?,
BookCli::Open => book::open()?,
}
},
DocKindCli::Homepage { task } => match task {
HomepageCli::Build => homepage::build()?,
},
};
Ok(())
}
Expand All @@ -59,16 +73,9 @@ pub mod book {

#[tracing::instrument]
pub fn build() -> crate::Result {
util::install_crate(Crate::Mdbook)?;
util::install_crate(Crate::MdbookPlantuml)?;

let out_dir = out_dir();

Command::new("mdbook")
.arg("build")
.arg("--dest-dir").arg(&out_dir)
.current_dir(doc_dir())
.run_requiring_success()?;
create_md_book_command(&out_dir)?;

log::info!("Placed distribution into: {}", out_dir.display());

Expand All @@ -83,3 +90,48 @@ pub mod book {
crate::constants::target_dir().join("book")
}
}

pub mod homepage {
use super::*;

#[tracing::instrument]
pub fn build() -> crate::Result {
let out_dir = out_dir();

create_md_book_command(&out_dir)?;

Command::new("cp")
.arg("--recursive")
.arg("--update")
.arg(&homepage_source_dir())
.arg(&out_dir)
.run_requiring_success()?;

log::info!("Placed distribution into: {}", out_dir.display());

Ok(())
}

fn homepage_source_dir() -> PathBuf { crate::constants::workspace_dir().join("opendut-homepage/.") }

fn out_dir() -> PathBuf {
crate::constants::target_dir().join("homepage")
}
}

fn create_md_book_command(out_dir: &PathBuf) -> crate::Result {
util::install_crate(Crate::Mdbook)?;
util::install_crate(Crate::MdbookPlantuml)?;

Command::new("mdbook")
.arg("build")
.arg("--dest-dir").arg(&out_dir.join("book"))
.current_dir(doc_dir())
.run_requiring_success()?;
Ok(())
}

fn doc_dir() -> PathBuf {
crate::constants::workspace_dir().join("doc")
}

30 changes: 30 additions & 0 deletions .github/workflows/homepage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: homepage
on:
workflow_dispatch: # manual trigger
inputs:
run-testenv:
description: "Run the build and deployment process of the OpenDuT homepage."
required: false
type: string
default: "false"
pull_request:
types: [ opened, reopened, synchronize, edited, ready_for_review ]
push:
branches: [
"main",
"development"
]
tags:
- v[0-9]+.[0-9]+.[0-9]+
- v[0-9]+.[0-9]+.[0-9]+-*
- canary

jobs:
homepage:
uses: ./.github/workflows/job-homepage.yaml
permissions:
contents: read
pages: write
id-token: write
with:
runs-on: "${{ vars.OPENDUT_GH_RUNNER_LARGE || '[\"ubuntu-latest\"]' }}"
73 changes: 73 additions & 0 deletions .github/workflows/job-homepage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: homepage
on:
workflow_call: # allow this workflow to be called from other workflows
inputs:
runs-on:
default: "['ubuntu-latest']"
required: false
type: string

jobs:
check_documentation_changed:
name: Check if documentation has changed and a new deploy is needed
runs-on: ${{ fromJson(inputs.runs-on) }}
outputs:
documentation: ${{ steps.filter.outputs.documentation }}
steps:
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # https://github.com/dorny/paths-filter/tree/v3.0.2
id: filter
with:
filters: |
documentation:
- 'doc/**'
- 'opendut-homepage/**'
base: main

build_homepage:
name: Build the homepage and upload artifact
if: ${{ needs.check_documentation_changed.outputs.documentation == 'true' && (github.ref_name == 'main' || github.ref_name == 'development' || github.ref_type == 'tag') }}
runs-on: ${{ fromJson(inputs.runs-on) }}
needs: check_documentation_changed
steps:
- name: Checkout sources
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab

- name: Configure GitHub Pages
uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b

- name: Rust setup
uses: ./.github/actions/rust-setup

- name: Build homepage
run: cargo ci doc homepage build

- name: Upload homepage artifact
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8
with:
name: "homepage"
path: "./target/ci/homepage"
if-no-files-found: error
retention-days: 1

- name: Upload GitHub Pages artifact
uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa
with:
path: "./target/ci/homepage"

deploy_homepage:
name: Deploy the created homepage artifacts to GitHub Pages
if: ${{ needs.check_documentation_changed.outputs.documentation == 'true' && (github.ref_name == 'main' || github.ref_name == 'development' || github.ref_type == 'tag') }}
permissions:
contents: read
pages: write
id-token: write
runs-on: ${{ fromJson(inputs.runs-on) }}
needs: build_homepage
environment:
name: github-pages
url: ${{steps.deployment.outputs.page_url}}
steps:
- name: Deploy artifact
id: deployment
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e
1 change: 1 addition & 0 deletions opendut-homepage/CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
opendut.eclipse.dev
4 changes: 4 additions & 0 deletions opendut-homepage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Eclipse openDuT Project Page

Webpage for the Eclipse openDuT project.

43 changes: 43 additions & 0 deletions opendut-homepage/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Eclipse openDuT</title>
<link href="resources/bulma.css" rel="stylesheet" />
<style>
#logo, #funded_by_the_european_union {
max-width: 50%;
}
body {
padding: 1rem;
margin: auto;
max-width: 50rem;
}
</style>
<meta name="viewport" content="width=device-width,initial-scale=1" />
</head>
<body>
<img
id="logo"
src="resources/logos/logo_light.png"
alt="Eclipse openDuT"
/>
<br>
<br>
<p>
Test Electronic Control Units around the world in a transparent network.
</p>
<br>
<a class="button" href="https://projects.eclipse.org/projects/automotive.opendut">Eclipse Project</a>
<a class="button" href="book/index.html">Documentation</a>
<a class="button" href="https://github.com/eclipse-opendut/opendut/">Code</a>

<hr>

<img
id="funded_by_the_european_union"
src="resources/logos/funded_by_the_european_union.svg"
alt="Funded by the European Union"
/>
</body>
</html>
Loading

0 comments on commit 9382be2

Please sign in to comment.