.github/workflows/runner.yaml #670
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
| on: | |
| workflow_dispatch: {} | |
| schedule: | |
| - cron: '0 0 * * *' # daily | |
| permissions: | |
| contents: write | |
| jobs: | |
| prepare-matrix: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| steps: | |
| - uses: actions/checkout@v2 | |
| - name: Set up Python environment | |
| uses: actions/setup-python@v2 | |
| - name: Install YAML processing tool | |
| run: pip install yq | |
| - name: Convert YAML to JSON | |
| id: yaml-to-json | |
| run: | | |
| echo "Converting YAML to JSON" | |
| JSON=$(yq '[.vmps[].snomed_code]' config.yaml) | |
| echo "Matrix JSON: $JSON" | |
| echo "::set-output name=matrix::$(echo $JSON)" | |
| - name: Set matrix for next job | |
| id: set-matrix | |
| run: | | |
| MATRIX_JSON='${{ steps.yaml-to-json.outputs.matrix }}' | |
| echo "Matrix: $MATRIX_JSON" | |
| echo "::set-output name=matrix::$MATRIX_JSON" | |
| grab-data: | |
| runs-on: ubuntu-latest | |
| needs: prepare-matrix | |
| strategy: | |
| max-parallel: 1 | |
| matrix: | |
| arg: ${{fromJson(needs.prepare-matrix.outputs.matrix)}} | |
| steps: | |
| - uses: actions/checkout@v2 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Python environment | |
| uses: actions/setup-python@v2 | |
| with: | |
| python-version: 3.11 | |
| - name: Install dependencies | |
| run: pip install -r requirements.txt | |
| - name: Grab data | |
| run: python fetch_stock.py scrape ${{ matrix.arg }} | |
| - name: Upload data | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: output-${{ matrix.arg }} | |
| path: tmp/ | |
| process-data: | |
| needs: grab-data | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v2 | |
| with: | |
| ref: ${{ github.ref_name }} | |
| - name: Set up Python environment | |
| uses: actions/setup-python@v2 | |
| with: | |
| python-version: 3.11 | |
| - name: Install dependencies | |
| run: pip install -r requirements.txt | |
| - name: Download data | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: tmp/ | |
| merge-multiple: true | |
| - name: Debug tmp contents | |
| run: ls -R tmp/ | |
| - name: Combine scraped shortages data | |
| run: python fetch_stock.py combine | |
| - name: Get latest stores data | |
| run: python grab_stores.py | |
| - name: Generate maps | |
| run: python make_map.py | |
| - name: Make index | |
| run: python make_index.py | |
| - name: Check for Changes | |
| id: git-check | |
| run: | | |
| set -x | |
| # check for changes | |
| has_changes=$(git diff --name-only outputs/) | |
| echo "has_changes is: $has_changes" | |
| untracked_files=$(git ls-files --others --exclude-standard outputs/) | |
| echo "untracked_files is: $untracked_files" | |
| if [ -n "$untracked_files" ] || [ -n "$has_changes" ]; then | |
| echo "git-changes=1" >> $GITHUB_ENV | |
| else | |
| echo "git-changes=0" >> $GITHUB_ENV | |
| fi | |
| - name: Debug exit code env | |
| run: | | |
| echo "Debug changes:" | |
| echo ${{ env.git-changes }} | |
| - name: Configure Git | |
| run: | | |
| git config --local user.email "[email protected]" | |
| git config --local user.name "GitHub Action" | |
| - name: Commit and Push Output | |
| if: env.git-changes == '1' | |
| run: | | |
| git add outputs/ | |
| git commit -m "Add output from GitHub Action" | |
| git push |