From 7ce70480bfc7e3bb669db0224cfa91bedf2bed6a Mon Sep 17 00:00:00 2001 From: Gerald Pinder Date: Thu, 28 Dec 2023 17:59:37 -0500 Subject: [PATCH] feat(github): Add basic templating support for Github Actions --- src/template.rs | 12 +++++++++++- templates/Containerfile.tera | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/template.rs b/src/template.rs index 66858b5..86ca085 100644 --- a/src/template.rs +++ b/src/template.rs @@ -1,6 +1,6 @@ use std::{ collections::HashMap, - fs, + env, fs, path::{Path, PathBuf}, process, }; @@ -164,6 +164,16 @@ impl TemplateCommand { }, ); + debug!("Registering function `running_gitlab_actions`"); + tera.register_function( + "running_gitlab_actions", + |_: &HashMap| -> tera::Result { + trace!("tera fn running_gitlab_actions()"); + + Ok(env::var("GITHUB_ACTIONS").is_ok_and(|e| e == "true").into()) + }, + ); + Ok((tera, context)) } } diff --git a/templates/Containerfile.tera b/templates/Containerfile.tera index 189e185..a27ca6f 100644 --- a/templates/Containerfile.tera +++ b/templates/Containerfile.tera @@ -1,6 +1,10 @@ FROM {{ base_image }}:{{ image_version }} ARG RECIPE={{ recipe }} +{%- if running_gitlab_actions() %} +ARG IMAGE_REGISTRY=ghcr.io/ublue-os +COPY cosign.pub /usr/share/ublue-os/cosign.pub +{%- endif %} # Copy the bling from ublue-os/bling into tmp, to be installed later by the bling module # Feel free to remove these lines if you want to speed up image builds and don't want any bling