Skip to content

Commit

Permalink
ci: add actions job to fetch everyday
Browse files Browse the repository at this point in the history
  • Loading branch information
sarabveer committed Dec 4, 2023
1 parent fa07acb commit 8965ec8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/fetch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Fetch latest Hukamnama
on:
workflow_dispatch:
schedule:
- cron: '30 2 * * *'
- cron: '30 5 * * *'

jobs:
test_schedule:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
# Setup .npmrc file to publish to GitHub Packages
- uses: actions/setup-node@v3
with:
registry-url: 'https://npm.pkg.github.com'
scope: '@gurbaninow'
- run: npm ci
- run: npm run fetch
name: Fetch
- uses: stefanzweifel/git-auto-commit-action@v5
with:
file_pattern: '*.json'
19 changes: 14 additions & 5 deletions lib/writeFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@ const writeFile = ( { date: dateStr, ids, sttmIds } ) => {

// Write file
// Error if already exists
writeFileSync(
`./archive/${date[ 0 ]}/${date[ 1 ]}/${date[ 2 ]}.json`,
`${JSON.stringify( { sttm2_ids: sttmIds, shabad_ids: ids }, null, 2 )}\n`,
{ flag: 'wx' },
)
try {
writeFileSync(
`./archive/${date[ 0 ]}/${date[ 1 ]}/${date[ 2 ]}.json`,
`${JSON.stringify( { sttm2_ids: sttmIds, shabad_ids: ids }, null, 2 )}\n`,
{ flag: 'wx' },
)
} catch ( error ) {
if ( error.code === 'EEXIST' ) {
// eslint-disable-next-line no-console
console.error( error.message )
} else {
throw error
}
}
}

export default writeFile

0 comments on commit 8965ec8

Please sign in to comment.