Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented AMBER_HEADER and AMBER_FOOTER variables #682

Open
wants to merge 4 commits into
base: staging
Choose a base branch
from

Conversation

Thesola10
Copy link

This fixes #344 and #672 by introducing an AMBER_HEADER variable that points to the customizable header file, as well as an AMBER_FOOTER variable to optionally append raw data to the end of the script.

Again, this is a proof-of-concept, and it stands to reason that it could be implemented in a better way, but this can serve as a starting point.

@lens0021 lens0021 changed the base branch from main to staging March 1, 2025 01:30
@b1ek
Copy link
Member

b1ek commented Mar 10, 2025

i've edited this a bit to be more consistent with the rest of our codebase and i think this is ready to be reviewed & merged.

i also hardcoded newline between header and footer to prevent the first line being commented out if the user supplies their own header which doesn't have a newline at the end, like this:

long text with code
echo "hi!"
# my custom header
# amber version: 1.4.0echo hi!

@b1ek b1ek marked this pull request as ready for review March 10, 2025 08:49
@b1ek b1ek requested review from hdwalters and Ph0enixKM and removed request for hdwalters March 10, 2025 08:50
Copy link
Member

@Ph0enixKM Ph0enixKM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to keep the date? Since the produced output can have a different date based on the same input, this breaks the reproducible build principle. Perhaps should we let the OS store the creation date in the file's metadata.

@@ -1,4 +1,4 @@
#!/usr/bin/env bash
# Written in [Amber](https://amber-lang.com/)
# version: {{ version }}
# date: {{ date }}
# date: {{ date }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding newline in the end of the file

Suggested change
# date: {{ date }}
# date: {{ date }}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've outlined before why it has to be hardcoded, so adding a newline here would mean that there are two newlines in the output

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes. We could header.trim_end() so that this file can be saved properly. Developers using custom headers would have to remember not to put the additional line too.

Comment on lines +202 to +221

let header_template =
if let Ok(dynamic) = env::var("AMBER_HEADER") {
fs::read_to_string(dynamic.to_string()).expect(format!("Couldn't read the dynamic header file from {dynamic}").as_str())
} else {
include_str!("header.sh").to_string()
};

let footer_template =
if let Ok(dynamic) = env::var("AMBER_FOOTER") {
fs::read_to_string(dynamic.to_string()).expect(format!("Couldn't read the dynamic footer file from {dynamic}").as_str())
} else {
String::new()
};

let header = header_template
.replace("{{ version }}", env!("CARGO_PKG_VERSION"))
.replace("{{ date }}", now.as_str());

let footer = footer_template
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section is pretty long and adds up to the length of the translate method. Would you consider extracting it to a new private gen_header (or something similar) method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Make Amber header in generated Bash files configurable
3 participants