Skip to content

Commit

Permalink
fix: generate previews from forked repos
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaolou86 committed Feb 2, 2024
1 parent f580c2c commit 6fb296d
Showing 1 changed file with 114 additions and 21 deletions.
135 changes: 114 additions & 21 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,129 @@ on:
push:

jobs:
release-version:
name: Releasing a version

test-deploy:
name: Test deploy
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message, 'chore') || (github.ref_name == 'main' && !contains(github.event.head_commit.message, 'chore(release)')) }}
steps:
- uses: actions/checkout@v2
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
token: ${{ secrets.USER_TOKEN }}
node-version: 16

- uses: actions/setup-node@v2
- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: 16

- name: Install node_modules
run: yarn

- name: Authenticate with GitHub
run: |
git config --global user.name "${{ secrets.USER_NAME }}"
git config --global user.email "${{ secrets.USER_EMAIL }}"
- name: Generate Site
run: yarn generate

- name: "Upload generated content"
uses: actions/upload-artifact@v2
with:
name: starknet-site
if-no-files-found: error
path:
public_html

publish:
name: deploy-review
runs-on: ubuntu-latest
needs:
- test-deploy
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
node-version: 16
ref: gh-pages
#USER_TOKEN: ${{ secrets.USER_TOKEN }}

- name: Run release script
if: ${{ github.ref_name == 'main' }}
run: yarn run release
- name: Extract PR details
id: pr
run: |
PR_ID=pr-${{ github.event.pull_request.number }}
PREVIEW_PATH=previews/${PR_ID}
echo "::set-output name=PR_ID::${PR_ID}"
- name: Push to remote branch
uses: ad-m/github-push-action@master
- name: "Remove preview build directory"
run: rm -rf ${{ steps.pr.outputs.PR_ID }}
- name: "Create preview build directory"
run: mkdir -p ${{ steps.pr.outputs.PR_ID }}
- name: "Download generated content"
uses: actions/download-artifact@v2
with:
USER_TOKEN: ${{ secrets.USER_TOKEN }}
branch: ${{ github.ref }}
tags: true
force: true
name: starknet-site
path: ${{ steps.pr.outputs.PR_ID }}

- name: PR preview details
run:
echo "you can preview the PR at https://starknet-io.github.io/starknet-docs/${{ steps.pr.outputs.PR_ID }}/documentation/"

- name: "Commit changes"
run: |
set -euo pipefail
# Debug information
echo "Current directory: $(pwd)"
echo "Contents of the repository:"
ls -al
echo "Git status:"
git status
git config -l
git add .
if ! git diff-index --quiet HEAD --; then
# Debug information
echo "Changes detected. Committing and pushing changes."
commit_message="Adding or updating preview build for PR ${{ steps.pr.outputs.PR_ID }}"
# Debug message
echo "Commit message: $commit_message"
# Commit changes
git commit -m "$commit_message"
# Check if commit was successful
if [ $? -eq 0 ]; then
# Debug information
echo "Commit successful. Pushing changes."
# Push changes
git push --set-upstream origin gh-pages
# Check if push was successful
if [ $? -eq 0 ]; then
# Debug information
echo "Push successful."
else
# Debug information
echo "Error: Push failed."
fi
else
# Debug information
echo "Error: Commit failed."
fi
else
# Debug information
echo "No changes found."
fi
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

- name: "Send comment to PR"
continue-on-error: true
run: |
set -euo pipefail
echo "Your preview build is ready! ✨ Check the following link in 1-2 minutes: https://starknet-io.github.io/starknet-docs/${{ steps.pr.outputs.PR_ID }}/documentation/ ." >/tmp/comment
gh pr comment ${{ github.event.pull_request.number }} -F /tmp/comment
env:
# USER_TOKEN: "${{ secrets.USER_TOKEN }}"
GH_TOKEN: "${{ github.token }}"

0 comments on commit 6fb296d

Please sign in to comment.