Daily Job #227
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: Daily Job | |
on: | |
schedule: | |
- cron: '0 0 * * *' | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '20' | |
- name: Install dependencies | |
run: npm install | |
- name: Run your application | |
env: | |
GMAIL_USER: ${{ secrets.GMAIL_USER }} | |
GMAIL_PASSWORD: ${{ secrets.GMAIL_PASSWORD }} | |
run: npm start | |
- name: Check for Uncommitted Changes | |
id: changes | |
run: | | |
if git diff-index --quiet HEAD; then | |
echo "has_changes=false" >> $GITHUB_ENV | |
else | |
echo "has_changes=true" >> $GITHUB_ENV | |
fi | |
- name: Log and Exit if No Changes | |
if: env.has_changes == 'false' | |
run: echo "No changes to commit. Exiting." | |
- name: Install jq | |
if: env.has_changes == 'true' | |
run: sudo apt-get update && sudo apt-get install -y jq | |
- name: Check for Existing Pull Request | |
if: env.has_changes == 'true' | |
id: check_pr | |
run: | | |
PR_EXISTS=$(gh pr list --base main --head version-updates --json number --jq '.[].number') | |
if [ -n "$PR_EXISTS" ]; then | |
echo "pr_exists=true" >> $GITHUB_ENV | |
echo "Pull request already exists: #$PR_EXISTS" | |
else | |
echo "pr_exists=false" >> $GITHUB_ENV | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Commit and Push Changes | |
if: env.pr_exists == 'false' && env.has_changes == 'true' | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "aryamohanan" | |
git checkout -b version-updates | |
# Stage all changes | |
git add . | |
# Check for changes to be committed | |
if git diff-index --cached --quiet HEAD; then | |
echo "No changes to commit. Exiting." | |
exit 0 | |
fi | |
# Commit and push changes | |
git commit -m "Update .version file" | |
git push origin version-updates | |
- name: Create Pull Request | |
if: env.pr_exists == 'false' && env.has_changes == 'true' | |
run: gh pr create -B main -H version-updates --title 'Update Node.js version' --body 'Node.js releases a new version.' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Skip PR Creation | |
if: env.pr_exists == 'true' | |
run: echo "Pull request already exists. Skipping PR creation." |