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

Add GH action to push hydrogen theme to external repo #4

Merged
merged 1 commit into from
Nov 16, 2023
Merged
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
78 changes: 78 additions & 0 deletions .github/workflows/push-to-external-repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: (main) push to external repo

on:
push:
branches:
- main
paths:
- "templates/hydrogen-theme/**"
pull_request:
branches:
- main

jobs:
push-to-external-repo:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Determine branch
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
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

- name: Generate pull request comment
id: pr_comment
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
preview_url="https://headless-clone-git-${{ steps.branch.outputs.branch }}-thomaskn1.vercel.app"
echo "body=A preview URL is being deployed to test this PR. It should be live in a short moment: ${preview_url}" >> $GITHUB_OUTPUT
fi

- name: Check Existing Comments
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: steps.check-comments.outputs.existingCommentFound != '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 }}`
});
Loading