Skip to content

Commit

Permalink
investigate output problems
Browse files Browse the repository at this point in the history
  • Loading branch information
vcanales committed Apr 12, 2024
1 parent ff57b61 commit c659bc1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 52 deletions.
55 changes: 37 additions & 18 deletions .github/workflows/preview-theme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,60 @@ jobs:
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
# save only the basename
unique_dirs[$dir_name]=$(basename $dir_name)
echo $unique_dirs
fi
done
# Check if any themes have changed
# Check if themes have changed
if [[ ${#unique_dirs[@]} -eq 0 ]]; then
echo "No themes have changed"
echo "No theme changes detected"
echo "HAS_THEME_CHANGES=false" >> $GITHUB_OUTPUT
exit 78 # Exit with neutral status code
exit 78 # Use neutral exit code
fi
# Output list of theme slugs with changes
echo "HAS_THEME_CHANGES=true" >> $GITHUB_OUTPUT
echo "CHANGED_THEMES=$(echo ${unique_dirs[@]})" >> $GITHUB_ENV
echo "Theme directories with changes: $CHANGED_THEME_DIRS"
# 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
# parse preview links into a json array, and minify the output into a single line
preview_links=$(echo "${preview_links[@]}" | jq -R . | jq -s . | jq -c .)
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 = JSON.parse(process.env.PREVIEW_LINKS);
const comment = previewLinks.join('\n');
const createBlueprint = ( themeSlug, branch ) => {
const template = {
steps: [
{
step: 'login',
username: 'admin',
password: 'password'
}
{
step: 'installTheme',
themeZipFile: {
resourece: 'url',
url: `https://github-proxy.com/partial/Automattic/themes/${themeSlug}?branch=${branch}`
}
}
{
step: 'activateTheme',
themeFolderName: themeSlug
}
]
};
return JSON.stringify(template);
};
const comment = process.env.CHANGED_THEMES.split(' ').map(themeSlug => {
const theme = themeSlug.split('/').pop();
return `- [Preview changes for ${theme}](https://playground.wordpress.net/#${createBlueprint(themeSlug, context.payload.pull_request.head.ref)})`;
}).join('\n');
// Check if a comment already exists
const { data: comments } = await github.rest.issues.listComments({
Expand Down
34 changes: 0 additions & 34 deletions bin/generate-preview-link.sh

This file was deleted.

0 comments on commit c659bc1

Please sign in to comment.