NC Data #74
This file contains hidden or 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: 'NC Data' | |
| 'on': | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'raw-data/*NC_DETECT*.csv' | |
| schedule: | |
| - cron: '30 4 * * *' | |
| workflow_dispatch: | |
| permissions: | |
| contents: 'write' | |
| jobs: | |
| update: | |
| name: 'update' | |
| if: "${{ github.repository == 'ACCIDDA/flu-metrocast-nc' && github.event_name != 'schedule' }}" | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 'set date' | |
| id: 'date' | |
| run: | | |
| echo "DATE=$(date -u +'%Y-%m-%d')" >> $GITHUB_ENV | |
| - name: 'checkout repository' | |
| uses: 'actions/checkout@v6' | |
| with: | |
| ref: 'main' | |
| fetch-depth: 0 | |
| - name: 'sync fork' | |
| run: | | |
| gh repo sync \ | |
| --branch "main" \ | |
| --source "reichlab/flu-metrocast" \ | |
| "ACCIDDA/flu-metrocast-nc" | |
| env: | |
| DATE: "${{ env.DATE }}" | |
| GH_TOKEN: "${{ secrets.FLU_METROCAST_NC }}" | |
| - name: 'setup R' | |
| uses: r-lib/actions/setup-r@v2 | |
| - name: 'apt update' | |
| run: 'sudo apt-get update' | |
| - name: 'install dependencies' | |
| uses: 'r-lib/actions/setup-r-dependencies@v2' | |
| with: | |
| packages: | | |
| any::sessioninfo | |
| any::magrittr | |
| any::dplyr | |
| any::tidyr | |
| any::purrr | |
| any::lubridate | |
| any::readr | |
| - name: 'run NC update script' | |
| run: 'Rscript ./src/NC_clean.R' | |
| - name: 'configure git' | |
| run: | | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| env: | |
| GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | |
| - name: 'commit and push changes' | |
| run: | | |
| git add -A | |
| if git diff --cached --quiet; then | |
| echo "No changes to commit." | |
| echo "CHANGES=false" >> $GITHUB_ENV | |
| exit 0 | |
| fi | |
| git commit -m "Update NC target data for $DATE" | |
| git pull --rebase origin main | |
| git push origin main | |
| echo "CHANGES=true" >> $GITHUB_ENV | |
| env: | |
| DATE: "${{ env.DATE }}" | |
| GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | |
| - name: 'create pull request' | |
| if: "${{ env.CHANGES == 'true' }}" | |
| run: | | |
| PULL_REQUEST_LINK=$(gh pr create \ | |
| --repo "reichlab/flu-metrocast" \ | |
| --head "ACCIDDA:main" \ | |
| --base "main" \ | |
| --title "Update NC target data for $DATE" \ | |
| --body "Automated update of NC target data for $DATE. cc: @CyGei, @Mmietchen, @TimothyWillard.") | |
| echo "PULL_REQUEST_LINK=$PULL_REQUEST_LINK" >> $GITHUB_ENV | |
| env: | |
| DATE: "${{ env.DATE }}" | |
| GH_TOKEN: "${{ secrets.FLU_METROCAST_NC }}" | |
| - name: 'success slack alert (no pr)' | |
| uses: 'slackapi/slack-github-action@v2.1' | |
| if: "${{ success() && env.CHANGES == 'false' }}" | |
| with: | |
| webhook: "${{ secrets.NC_METROCAST_WEBHOOK_URL }}" | |
| webhook-type: 'incoming-webhook' | |
| payload: | | |
| { | |
| "blocks": [ | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": ":white_check_mark: *NC Data Update Succeeded*" | |
| } | |
| }, | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": "_No changes detected, no pull request created._" | |
| } | |
| }, | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": "<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Link to successful action run ${{ github.run_id }}.>" | |
| } | |
| } | |
| ] | |
| } | |
| - name: 'success slack alert (pr created)' | |
| uses: 'slackapi/slack-github-action@v2.1' | |
| if: "${{ success() && env.CHANGES == 'true' }}" | |
| with: | |
| webhook: "${{ secrets.NC_METROCAST_WEBHOOK_URL }}" | |
| webhook-type: 'incoming-webhook' | |
| payload: | | |
| { | |
| "blocks": [ | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": ":white_check_mark: *NC Data Update Succeeded*" | |
| } | |
| }, | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": "<${{ env.PULL_REQUEST_LINK }}|Link to pull request.>" | |
| } | |
| }, | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": "<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Link to successful action run ${{ github.run_id }}.>" | |
| } | |
| } | |
| ] | |
| } | |
| - name: 'failure slack alert (non-manual trigger)' | |
| uses: 'slackapi/slack-github-action@v2.1' | |
| if: "${{ failure() && github.event_name != 'workflow_dispatch' }}" | |
| with: | |
| webhook: "${{ secrets.NC_METROCAST_WEBHOOK_URL }}" | |
| webhook-type: 'incoming-webhook' | |
| payload: | | |
| { | |
| "blocks": [ | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": ":x: *NC Data Update Failed*" | |
| } | |
| }, | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": "Please review promptly <!channel>." | |
| } | |
| }, | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": "<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Link to failed action run ${{ github.run_id }}.>" | |
| } | |
| } | |
| ] | |
| } | |
| - name: 'failure slack alert (manual trigger)' | |
| uses: 'slackapi/slack-github-action@v2.1' | |
| if: "${{ failure() && github.event_name == 'workflow_dispatch' }}" | |
| with: | |
| webhook: "${{ secrets.NC_METROCAST_WEBHOOK_URL }}" | |
| webhook-type: 'incoming-webhook' | |
| payload: | | |
| { | |
| "blocks": [ | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": ":x: *NC Data Update Failed*" | |
| } | |
| }, | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": "Triggered manually, so no @channel mention. Please review when convenient." | |
| } | |
| }, | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": "<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Link to failed action run ${{ github.run_id }}.>" | |
| } | |
| } | |
| ] | |
| } | |
| sync: | |
| name: 'sync' | |
| if: "${{ github.repository == 'ACCIDDA/flu-metrocast-nc' && github.event_name == 'schedule' }}" | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: 'set date' | |
| id: 'date' | |
| run: | | |
| echo "DATE=$(date -u +'%Y-%m-%d')" >> $GITHUB_ENV | |
| - name: 'checkout repository' | |
| uses: 'actions/checkout@v6' | |
| with: | |
| ref: 'main' | |
| fetch-depth: 0 | |
| - name: 'sync fork' | |
| run: | | |
| gh repo sync \ | |
| --branch "main" \ | |
| --source "reichlab/flu-metrocast" \ | |
| "ACCIDDA/flu-metrocast-nc" | |
| env: | |
| DATE: "${{ env.DATE }}" | |
| GH_TOKEN: "${{ secrets.FLU_METROCAST_NC }}" | |
| - name: 'failure slack alert' | |
| uses: 'slackapi/slack-github-action@v2.1' | |
| if: '${{ failure() }}' | |
| with: | |
| webhook: "${{ secrets.NC_METROCAST_WEBHOOK_URL }}" | |
| webhook-type: 'incoming-webhook' | |
| payload: | | |
| { | |
| "blocks": [ | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": ":x: *NC Data Sync Failed*" | |
| } | |
| }, | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": "Please review promptly <!channel>." | |
| } | |
| }, | |
| { | |
| "type": "section", | |
| "text": { | |
| "type": "mrkdwn", | |
| "text": "<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Link to failed action run ${{ github.run_id }}.>" | |
| } | |
| } | |
| ] | |
| } |