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 15, 2024
1 parent b97b3f5 commit 9b221d3
Show file tree
Hide file tree
Showing 7 changed files with 12,124 additions and 1 deletion.
69 changes: 68 additions & 1 deletion .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 Down Expand Up @@ -84,3 +98,56 @@ pub mod book {
crate::constants::target_dir().join("book")
}
}

pub mod homepage {
use super::*;

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

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


fs_extra::dir::copy(
&homepage_source_dir(),
&out_dir(),
&fs_extra::dir::CopyOptions::default()
.overwrite(true)
.content_only(true)
)?;

fs_extra::dir::create(
&logos_out_dir(),
true
)?;

for logo in RESOURCES_TO_INCLUDE {
fs_extra::file::copy(
&logos_source_dir().join(logo),
&logos_out_dir().join(format!("{}", logo)),
&fs_extra::file::CopyOptions::default()
.overwrite(true)
)?;
}

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

Ok(())
}

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

fn logos_source_dir() -> PathBuf { crate::constants::workspace_dir().join("resources/logos/") }

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

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

fn logos_out_dir() -> PathBuf { out_dir().join("resources/logos") }

const RESOURCES_TO_INCLUDE: [&str; 2] = ["logo_light.png", "funded_by_the_european_union.svg"];
}
84 changes: 84 additions & 0 deletions .github/workflows/homepage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
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]+-*

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' }}
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' }}
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
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 9b221d3

Please sign in to comment.