Merge branch 'richtext' #262
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: (main) push to external repo | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
push-to-external-repo: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Get all hydrogen theme files that have changed | |
id: changed-files-yaml | |
uses: tj-actions/changed-files@v40 | |
with: | |
files_yaml: | | |
hydrogen-theme: | |
- 'templates/hydrogen-theme/**' | |
- name: Determine branch | |
if: steps.changed-files-yaml.outputs.hydrogen-theme_any_changed == 'true' | |
id: branch | |
run: | | |
if [ "${{ github.event_name }}" == "pull_request" ]; then | |
pr_number="${{ github.event.number }}" | |
echo "branch=pull-request-${pr_number}" >> $GITHUB_OUTPUT | |
else | |
echo "branch=main" >> $GITHUB_OUTPUT | |
fi | |
- name: Publish to external repository | |
if: steps.changed-files-yaml.outputs.hydrogen-theme_any_changed == 'true' | |
uses: peaceiris/actions-gh-pages@v3 | |
with: | |
deploy_key: ${{ secrets.SSH_DEPLOY_KEY }} | |
publish_dir: ./templates/hydrogen-theme | |
external_repository: ${{ vars.EXTERNAL_REPO }} | |
publish_branch: ${{ steps.branch.outputs.branch }} | |
allow_empty_commit: true | |
exclude_assets: false | |
- name: Generate pull request comment | |
if: github.event_name == 'pull_request' && steps.changed-files-yaml.outputs.hydrogen-theme_any_changed == 'true' | |
id: pr_comment | |
run: | | |
preview_url="https://headless-clone-git-${{ steps.branch.outputs.branch }}-thomaskn1.vercel.app" | |
echo "body=We detected changes to a template. A preview URL is being deployed. It will be live in a short moment: ${preview_url}" >> $GITHUB_OUTPUT | |
- name: Check Existing Comments | |
if: github.event_name == 'pull_request' && steps.changed-files-yaml.outputs.hydrogen-theme_any_changed == 'true' | |
id: check-comments | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const existingComments = await github.rest.issues.listComments({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo | |
}); | |
const marker = "${{ steps.pr_comment.outputs.body }}" | |
const existingComment = existingComments.data.find(comment => comment.body.includes(marker)); | |
console.log(existingComment ? 'Existing comment found' : 'No existing comment found'); | |
// Set an output to pass information to subsequent steps | |
core.setOutput("existingCommentFound", existingComment ? 'true' : 'false'); | |
core.setOutput("existingCommentId", existingComment ? existingComment.id : ''); | |
- name: Comment on Pull Request | |
if: github.event_name == 'pull_request' && steps.check-comments.outputs.existingCommentFound != 'true' && steps.changed-files-yaml.outputs.hydrogen-theme_any_changed == 'true' | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `${{ steps.pr_comment.outputs.body }}` | |
}); |