Skip to content

Commit

Permalink
feat: automate creating PRs to push content updates for iamdeveloper.…
Browse files Browse the repository at this point in the history
…com (#61)
  • Loading branch information
nickytonline authored Nov 6, 2022
1 parent a4ffa74 commit 22a7282
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 20 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/get-latest-posts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,12 @@ jobs:
npm install
node --experimental-fetch bin/generateDevToPosts.js
node bin/generateHashnodeUrlMapping.js
- name: Commit changes
id: commit
- name: Setup git config
run: |
git config user.name 'token-generator-app[bot]'
git config user.email '82042599+token-generator-app[bot]@users.noreply.github.com'
- name: PR for Blog Post Updates
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
git pull origin main
git add .
if [[ -n "$(git status --porcelain)" ]]; then
git commit -m "chore (automated): update blog posts"
git push origin main
fi
./bin/pr-blog-posts.sh
16 changes: 6 additions & 10 deletions .github/workflows/get-latest-videos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@ jobs:
run: |
npm install
node bin/udpdateStreamingPage.js
- name: Commit changes
id: commit
- name: Setup git config
run: |
git config user.name 'token-generator-app[bot]'
git config user.email '82042599+token-generator-app[bot]@users.noreply.github.com'
- name: PR for Videos
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
git pull origin main
git add .
if [[ -n "$(git status --porcelain)" ]]; then
git commit -m "chore (automated): update videos"
git push origin main
fi
./bin/pr-videos.sh
20 changes: 20 additions & 0 deletions bin/pr-blog-posts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
PR_TITLE="chore (automated): update blog posts"
BRANCH_NAME="chore_automated_update_blog_posts_$(date +%s)"

git branch $BRANCH_NAME
git switch $BRANCH_NAME

# There are potentially multiple files if the blog post has images.
git add .

# See if we have any changes. We should.
if [[ -n "$(git status --porcelain)" ]]; then
echo "Creating PR \"$PR_TITLE\" for branch $BRANCH_NAME"
git commit -m "$PR_TITLE"
git push origin $BRANCH_NAME
gh pr create --title "$PR_TITLE" --body "This is an automated PR to update blog posts"
gh pr merge --auto --delete-branch --squash "$BRANCH_NAME"
else
# Shouldn't end up here, but log that there was nothing to sync
echo "Looks like there was nothing to update."
fi
20 changes: 20 additions & 0 deletions bin/pr-videos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
PR_TITLE="chore (automated): update videos"
BRANCH_NAME="chore_automated_update_videos_$(date +%s)"

git branch $BRANCH_NAME
git switch $BRANCH_NAME

# This is the only file we want to commit
git add src/pages/streaming.md

# See if we have any changes. We should.
if [[ -n "$(git status --porcelain)" ]]; then
echo "Creating PR \"$PR_TITLE\" for branch $BRANCH_NAME"
git commit -m "$PR_TITLE"
git push origin $BRANCH_NAME
gh pr create --title "$PR_TITLE" --body "This is an automated PR to update videos on the streaming page"
gh pr merge --auto --delete-branch --squash "$BRANCH_NAME"
else
# Shouldn't end up here, but log that there was nothing to sync
echo "Looks like there was nothing to update."
fi

0 comments on commit 22a7282

Please sign in to comment.