From 441183216752c3459e6834c891681e0cc6ca9c30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Sun, 15 Jan 2023 15:31:46 +0100 Subject: [PATCH] Add action to upload critical file (#1680) --- .github/workflows/upload-critical.yml | 73 +++++++++++++++++++++++++++ .github/workflows/upload-removed.yml | 4 +- 2 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/upload-critical.yml diff --git a/.github/workflows/upload-critical.yml b/.github/workflows/upload-critical.yml new file mode 100644 index 0000000..71873a4 --- /dev/null +++ b/.github/workflows/upload-critical.yml @@ -0,0 +1,73 @@ +name: Upload critical file to R2 + +on: + workflow_dispatch: + push: + branches: + - master + paths: + - critical + +concurrency: + cancel-in-progress: true + group: upload-critical + +jobs: + upload: + runs-on: ubuntu-latest + name: Upload + steps: + - name: Checkout the repository + uses: actions/checkout@v3.2.0 + + - name: Set up Python + uses: actions/setup-python@v4.4.0 + id: python + with: + python-version: "3.x" + + - name: Install AWS CLI + run: | + pip3 install \ + --disable-pip-version-check install \ + --ignore-installed \ + awscli + + - name: Handle the critical file + run: | + mkdir -p upload/critical + jq -c . < critical > upload/critical/data.json + jq -c '[.[].repository]' < critical > upload/critical/repositories.json + + - name: Upload artifacts + uses: actions/upload-artifact@v3 + with: + name: critical + path: upload/critical + if-no-files-found: error + + - name: Upload to R2 + run: | + aws s3 sync \ + upload/critical \ + s3://data-v2/critical \ + --endpoint-url ${{ secrets.CF_R2_ENDPOINT_DATA }} + env: + AWS_ACCESS_KEY_ID: ${{ secrets.CF_R2_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.CF_R2_SECRET_ACCESS_KEY }} + + - name: Bust Cloudflare cache + run: | + curl --silent --show-error --fail -X POST \ + "https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE_ID }}/purge_cache" \ + -H "Authorization: Bearer ${{ secrets.CF_BUST_CACHE_TOKEN }}" \ + -H "Content-Type: application/json" \ + --data '{"files": ["https:\/\/data-v2.hacs.xyz\/critical\/data.json", "https:\/\/data-v2.hacs.xyz\/critical\/repositories.json"]}' + + - name: Discord notification + if: ${{ github.event_name == 'schedule' && failure() }} + run: | + curl \ + -H "Content-Type: application/json" \ + -d '{"username": "GitHub action failure", "content": "[Scheduled action failed!](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}})"}' \ + ${{ secrets.DISCORD_WEBHOOK_ACTION_FAILURE }} diff --git a/.github/workflows/upload-removed.yml b/.github/workflows/upload-removed.yml index c9ac681..ef838ff 100644 --- a/.github/workflows/upload-removed.yml +++ b/.github/workflows/upload-removed.yml @@ -13,9 +13,9 @@ concurrency: group: upload-removed jobs: - removed: + upload: runs-on: ubuntu-latest - name: Removed + name: Upload steps: - name: Checkout the repository uses: actions/checkout@v3.2.0