Daily Job #149
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: Delete Existing Branch | |
if: env.has_changes == 'true' | |
run: | | |
if git show-ref --verify --quiet refs/heads/version-updates; then | |
git push origin --delete version-updates | |
git branch -D version-updates | |
fi | |
- name: Commit and Push Changes | |
if: 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.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 }} |