Automatically update data and commit
Tags: actionshackathon21, github
Published: 2021-11-25 18:18:47

[Instructions]: # (To submit to the GitHub Actions x DEV Hackathon 2021, please fill out all sections.)

### My Workflow
[Note]: # (Please make sure the project links to the appropriate GitHub Actions repository, and includes [an open source license](https://choosealicense.com/) and README.)

I just wrote an article about Github Actions, but I don't want to deprive you of this one! What is it about? For a single page application, various data sources are tapped. However, some data cannot be loaded directly from the application. For this reason I wrote a script that pulls, aggregates and formats the data.

In order for the data to be delivered with the application it must be committed into the repo. Then the regular CI pipeline runs, which builds and publishes the app:

![diagram of the workflow](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hwr15dbrjb0ibmw5rm0p.png)

The nice thing is that I don't have to do anything else, because the Github action runs itself on a regular basis, and every time it commits to the main branch, the CI pipeline runs.

The application was about getting a POC up and running quickly to tap into data from various sources and prepare it accordingly.

### Submission Category: Maintainer Must-Haves

[Note]: # (Maintainer Must-Haves, DIY Deployments, Interesting IoT, Phone Friendly, or Wacky Wildcards)


### Yaml File or Link to Code

[Note]: # (Our markdown editor supports pretty embeds. Try this syntax: `{% github link_to_your_repo %}` to share a GitHub repository)

The Github workflow consists of three main parts:

1. Setup
2. Execute script
3. Commit and push

```yaml
name: Update Polls and Execs

on:
  schedule:
    - cron: "5 18 * * 1"

jobs:
  resources:
    name: Update Polls and Execs
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1

      - uses: actions/setup-node@v1
        with:
          node-version: 14
      - run: npm install

      - name: Run script to update data
        run: npm run index

      - name: Push data
        uses: test-room-7/action-update-file@v1
        with:
          file-path: |
            src/app/constants/polls.constants.ts
            src/app/constants/proposals.constants.ts
          commit-msg: chore(data) update polls and execs
          github-token: ${{ secrets.GITHUB_TOKEN }}
```

The exciting thing about this action is the scheduled execution. Not everyone may be aware of this, but it can be used to map cron jobs that do their regular work.

### Additional Resources / Info

[Note:] # (Be sure to link to any open source projects that are using your workflow!)

[Note]: # (Be sure to include the DEV usernames of your collaborators, if any. )

[Reminder]: # (Submissions are due on December 8th, 2021 (11:59 PM PT or 2 AM ET/6 AM UTC on December 9th).

- The associated app can be found here: [https://delegates.makerlabs.one/](https://delegates.makerlabs.one/)
- Serves as a supplement to the MakerDAO Delegates program: [https://vote.makerdao.com/delegates](https://vote.makerdao.com/delegates)
- References:
  - [Github Actions / Scheduled Events](https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#scheduled-events)
  - [Action to update files](https://github.com/test-room-7/action-update-file)

Have fun!