Skip to content

chore: Screengrabs #1239

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions .github/workflows/screengrabs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Screengrabs

on:
workflow_dispatch:
pull_request:
types: [labeled, opened, synchronize]
paths:
- ".github/workflows/screengrabs.yml"

permissions:
contents: write
pull-requests: write

env:
TERM: "xterm-256color"
COLORTERM: "truecolor"
LANG: "en_US.UTF-8"
ATMOS_LOGS_LEVEL: "Info"

jobs:
prepare:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Get Atmos version
id: get-version
run: |
VERSION=$(curl -s https://api.github.com/repos/cloudposse/atmos/releases/latest | jq -r .tag_name)
echo "version=$VERSION" >> $GITHUB_OUTPUT

outputs:
version: ${{ steps.get-version.outputs.version }}

build:
needs: [prepare]
runs-on: ubuntu-latest
steps:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y aha util-linux make jq bat
sudo ln -s /usr/bin/batcat /usr/bin/bat

- name: Set Git Preferences for windows
run: |
git config --global core.autocrlf false
git config --global core.eol lf

- name: Checkout repository
uses: actions/checkout@v4

- name: Install Atmos
uses: jaxxstorm/[email protected]
with:
repo: cloudposse/atmos
tag: ${{ needs.prepare.outputs.version }}
chmod: 0755
extension-matching: disable
rename-to: atmos

- uses: hashicorp/setup-terraform@v3
with:
terraform_wrapper: false

- name: Run make build-all install
run: |
make -C demo/screengrabs build-all install
git add -A
git status

- name: Create or update PR
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: "chore/update-build-screengrabs-for-${{ needs.prepare.outputs.version }}"
title: "Update screengrabs for ${{ needs.prepare.outputs.version }}"
delete-branch: true
sign-commits: true
commit-message: |
chore: update screengrabs for ${{ needs.prepare.outputs.version }}
body: |
This PR updates the screengrabs for Atmos version ${{ needs.prepare.outputs.version }}.
base: main
labels: "no-release"

4 changes: 2 additions & 2 deletions demo/screengrabs/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
INSTALL_PATH ?= ../../website/src/components/screengrabs
INSTALL_PATH ?= ../../website/src/components/Screengrabs
all: build-all install

# Write to /website/static/screengrab/
install:
install:
@echo "Installing screengrabs to $(INSTALL_PATH)"
@mkdir -p $(INSTALL_PATH)
@cp -a artifacts/* $(INSTALL_PATH)
Expand Down
97 changes: 61 additions & 36 deletions demo/screengrabs/build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,86 @@
set -e
export TERM=xterm-256color

# Ensure that the output is not paginated
export LESS=-X

# Determine the correct sed syntax based on the operating system
if [ "$(uname)" = "Darwin" ]; then
SED="$SED" # macOS requires '' for in-place editing
else
SED="sed -i" # Linux does not require ''
fi
Comment on lines +8 to +13
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix macOS sed in-place syntax
The assignment SED="$SED" is a no-op and won’t invoke sed correctly on Darwin. You need to include the empty string argument for BSD sed’s -i flag.

Apply this patch:

-if [ "$(uname)" = "Darwin" ]; then
-    SED="$SED" # macOS requires '' for in-place editing
+if [ "$(uname)" = "Darwin" ]; then
+    SED="sed -i ''"  # BSD sed: in-place requires an explicit empty suffix
 else
-    SED="sed -i"    # Linux does not require ''
+    SED="sed -i"     # GNU sed: in-place works without suffix
 fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Determine the correct sed syntax based on the operating system
if [ "$(uname)" = "Darwin" ]; then
SED="$SED" # macOS requires '' for in-place editing
else
SED="sed -i" # Linux does not require ''
fi
# Determine the correct sed syntax based on the operating system
if [ "$(uname)" = "Darwin" ]; then
SED="sed -i ''" # BSD sed: in-place requires an explicit empty suffix
else
SED="sed -i" # GNU sed: in-place works without suffix
fi
🤖 Prompt for AI Agents (early access)
In demo/screengrabs/build-all.sh around lines 8 to 13, the macOS sed in-place
editing syntax is incorrect because the assignment SED="$SED" does nothing. Fix
this by setting SED to "sed -i ''" for Darwin to correctly use BSD sed's
in-place editing with an empty string argument, while keeping the Linux case as
"sed -i".


function record() {
local demo=$1
local demo=$1
local command=$2
local extension="${command##*.}" # if any...
local demo_path=../../examples/$demo
local extension="${command##*.}" # if any...
local demo_path=../../examples/$demo
local output_base_file=artifacts/$(echo "$command" | sed -E 's/ -/-/g' | sed -E 's/ +/-/g' | sed 's/---/--/g' | sed 's/scripts\///' | sed 's/\.sh$//')
local output_html=${output_base_file}.html
local output_ansi=${output_base_file}.ansi
local output_dir=$(dirname $output_base_file)
local output_html=${output_base_file}.html
local output_ansi=${output_base_file}.ansi
local output_dir=$(dirname $output_base_file)

echo "Screengrabbing $command → $output_html"
mkdir -p "$output_dir"
rm -f $output_ansi
if [ "${extension}" == "sh" ]; then
script -q $output_ansi command $command > /dev/null
else
script -q $output_ansi bash -c "cd $demo_path && ($command)" > /dev/null
fi
postprocess_ansi $output_ansi
aha --no-header < $output_ansi > $output_html
postprocess_html $output_html
rm -f $output_ansi
mkdir -p "$output_dir"
rm -f $output_ansi
if [ "$(uname)" = "Darwin" ]; then
# macOS-specific syntax
if [ "${extension}" == "sh" ]; then
script -q $output_ansi command $command > /dev/null
else
script -q $output_ansi bash -c "cd $demo_path && ($command)" > /dev/null
fi
else
# Linux-specific syntax
if [ "${extension}" = "sh" ]; then
script -q -a $output_ansi -c "$command" > /dev/null
else
script -q -a $output_ansi -c "cd $demo_path && ($command)" > /dev/null
fi
fi
postprocess_ansi $output_ansi
aha --no-header < $output_ansi > $output_html
postprocess_html $output_html
rm -f $output_ansi
if [ -n "$CI" ]; then
sed -i -e '1,1d' -e '$d' $output_html
fi
}

postprocess_ansi() {
local file=$1
# Remove noise and clean up the output
sed -i '' '/- Finding latest version of/d' $file
sed -i '' '/- Installed hashicorp/d' $file
sed -i '' '/- Installing hashicorp/d' $file
sed -i '' '/Terraform has created a lock file/d' $file
sed -i '' '/Include this file in your version control repository/d' $file
sed -i '' '/guarantee to make the same selections by default when/d' $file
sed -i '' '/you run "terraform init" in the future/d' $file
sed -i '' 's/Resource actions are indicated with the following symbols.*//' $file
sed -i '' 's/^ *EOT/\n/g' $file
sed -i '' 's/ *<<EOT/\n/g' $file
sed -i '' 's/ *<<-EOT/\n/g' $file
sed -i '' -E 's/\[id=[a-f0-9]+\]//g' $file
sed -i '' -E 's/(\[id=http)/\n \1/g' $file
local file=$1
# Remove noise and clean up the output
$SED '/- Finding latest version of/d' $file
$SED '/- Installed hashicorp/d' $file
$SED '/- Installing hashicorp/d' $file
$SED '/Terraform has created a lock file/d' $file
$SED '/Include this file in your version control repository/d' $file
$SED '/guarantee to make the same selections by default when/d' $file
$SED '/you run "terraform init" in the future/d' $file
$SED 's/Resource actions are indicated with the following symbols.*//' $file
$SED '/Workspace .* doesn.t exist./d' $file
$SED '/You can create this workspace with the .* subcommand/d' $file
$SED '/or include the .* flag with the .* subcommand./d' $file

$SED 's/^ *EOT/\n/g' $file
$SED 's/ *<<EOT/\n/g' $file
$SED 's/ *<<-EOT/\n/g' $file
$SED -E 's/\[id=[a-f0-9]+\]//g' $file
$SED -E 's/(\[id=http)/\n \1/g' $file
}

postprocess_html() {
local file=$1
sed -i '' 's/color:blue/color:#005f87/g' $file
local file=$1
$SED 's/color:blue/color:#005f87/g' $file
$SED 's/color:#183691/color:#005f87/g' $file
}

manifest=$1

if [ -z "$manifest" ]; then
echo "Usage: $0 <manifest>"
exit 1
echo "Usage: $0 <manifest>"
exit 1
fi

demo=$(basename $manifest .txt)
Expand Down
2 changes: 1 addition & 1 deletion demo/screengrabs/scripts/demo-stacks/.demo.rc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ demo_name=$(basename $(pwd))
shopt -s expand_aliases

alias tree='tree -CF --gitignore -I ".git" -I "terraform.tfstate*" -I "*.tfvars.json" -I "cache*.txt"'
alias bat='bat --force-colorization --style header,numbers --theme="GitHub"'
alias bat='bat --force-colorization --style header,numbers --theme="GitHub" --paging=never'
alias cat='bat'

function clean() {
Expand Down