Skip to content

Generate playground previews for theme changes #25

Generate playground previews for theme changes

Generate playground previews for theme changes #25

Workflow file for this run

name: Preview Theme Changes
on:
pull_request:
jobs:
check-for-changes-to-themes:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Retrieved Theme Changes
id: check-for-changes
run: |
# Retrieve list of all changed files
git fetch origin trunk:trunk
changed_files=$(git diff --name-only HEAD origin/trunk)
# Loop through changed files and identify parent directories
declare -A unique_dirs
for file in $changed_files; do
dir_name=$(dirname "$file")
echo $dir_name
if [[ -f "$dir_name/style.css" ]]; then # Check if the directory contains a theme
unique_dirs["$dir_name"]=1 # Use associative array to keep directories unique
echo $unique_dirs
fi
done
# Check if any themes have changed
if [[ ${#unique_dirs[@]} -eq 0 ]]; then
echo "No themes have changed"
echo "HAS_THEME_CHANGES=false" >> $GITHUB_OUTPUT
exit 78 # Exit with neutral status code
fi
echo "HAS_THEME_CHANGES=true" >> $GITHUB_OUTPUT
# Generate preview links for each theme
preview_links=()
for dir in "${!unique_dirs[@]}"; do
theme_slug=$(basename "$dir")
preview_links+=(bash ./bin/generate-preview-link.sh "$theme_slug" "${{ github.event.pull_request.head.ref }}")
done
echo "PREVIEW_LINKS=${preview_links[@]}" >> $GITHUB_ENV
- name: Comment on PR
id: comment-on-pr
if: ${{ steps.check-for-changes.outputs.HAS_THEME_CHANGES == 'true' }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const previewLinks = process.env.PREVIEW_LINKS.split(' ');
const comment = previewLinks.map(link => `- [Preview](${link})`).join('\n');
github.rest.issues.createComment({
issue_number: ${{ github.event.pull_request.number }},
owner: context.repo.owner,
repo: context.repo.repo,
body: `Preview links for theme changes:\n${comment}`
});