Skip to content

Commit

Permalink
fix: try fix git workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
01Joseph-Hwang10 committed Aug 29, 2023
1 parent 8a01fc5 commit 21dd9ad
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:
shell: bash
env:
VARIANT: ${{ matrix.variants }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
./scripts/export-resume.sh $VARIANT
52 changes: 21 additions & 31 deletions scripts/export-resume.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

set -e

echo "Checking out gh-pages branch..."

git config --local user.email "[email protected]"
git config --local user.name "Github Actions"

git fetch --unshallow
git checkout -f "$BRANCH"
git pull

echo "Exporting resume to $FILENAME..."

RESUME_TYPE=$1
FILENAME="resume-$RESUME_TYPE.pdf"

Expand Down Expand Up @@ -54,8 +65,6 @@ li {
}
"""

echo "Exporting resume to $FILENAME..."

npx docs-to-pdf \
--initialDocURLs="$_initialDocURLs" \
--contentSelector="$_contentSelector" \
Expand All @@ -72,45 +81,26 @@ sudo apt-get install -y qpdf

qpdf --empty --pages "$_outputPDFFilename" 2-z -- "$FILENAME"

echo "Uploading $FILENAME to GitHub..."
echo "Move file to appropriate directory..."

# Repository information
OWNER="01Joseph-Hwang10"
REPO="01joseph-hwang10.github.io"
BRANCH="gh-pages"

# Path to the PDF file you want to upload
PDF_PATH="$FILENAME"

# Commit message
COMMIT_MESSAGE="Update $FILENAME"
FILEPATH="files/resume/$FILENAME"

# Upload PDF content as a blob
BLOB_SHA=$(curl -X POST -H "Authorization: token $TOKEN" \
-d "{\"content\":\"$(base64 -w 0 $PDF_PATH)\"}" \
"https://api.github.com/repos/$OWNER/$REPO/git/blobs" | jq -r '.sha')
mv "$FILENAME" "$FILEPATH"

BASE_TREE=$(curl -H "Authorization: token $TOKEN" \
"https://api.github.com/repos/$OWNER/$REPO/git/refs/heads/$BRANCH" | jq -r '.object.sha')

# Create a new tree with the blob
TREE_SHA=$(curl -X POST -H "Authorization: token $TOKEN" \
-d "{\"base_tree\":\"$BASE_TREE\",
\"tree\":[{\"path\":\"$PDF_PATH\",\"mode\":\"100644\",\"type\":\"blob\",\"sha\":\"$BLOB_SHA\"}]}" \
"https://api.github.com/repos/$OWNER/$REPO/git/trees" | jq -r '.sha')

PARENT=$(curl -H 'Authorization: token $TOKEN' \
"https://api.github.com/repos/$OWNER/$REPO/git/refs/heads/$BRANCH" | jq -r '.object.sha')
# Commit and push changes
COMMIT_MESSAGE="Update $FILENAME"

# Create a new commit
COMMIT_SHA=$(curl -X POST -H "Authorization: token $TOKEN" \
-d "{\"message\":\"$COMMIT_MESSAGE\",\"tree\":\"$TREE_SHA\",
\"parents\":[\"$PARENT\"]}" \
"https://api.github.com/repos/$OWNER/$REPO/git/commits" | jq -r '.sha')
git add "$FILEPATH"
git commit -m "$COMMIT_MESSAGE"
git push origin "$BRANCH"

# Update the branch reference to point to the new commit
curl -X PATCH -H "Authorization: token $TOKEN" \
-d "{\"sha\":\"$COMMIT_SHA\"}" \
"https://api.github.com/repos/$OWNER/$REPO/git/refs/heads/$BRANCH"
echo "Cleaning up..."

rm "$_outputPDFFilename"
rm "$FILEPATH"

0 comments on commit 21dd9ad

Please sign in to comment.