Skip to content

Commit

Permalink
Separate artifacts index update into separate workflow (#2888)
Browse files Browse the repository at this point in the history
* Separate artifacts index update into separate workflow

* Apply suggestions from code review

Co-authored-by: Jan Čermák <[email protected]>

---------

Co-authored-by: Jan Čermák <[email protected]>
  • Loading branch information
agners and sairon authored Oct 31, 2023
1 parent 54cab43 commit 2e8b66d
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 43 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/artifacts-index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Update artifacts index

on:
# Manual run for specified version
workflow_dispatch:
inputs:
version:
description: Version of HAOS to build index for
required: true
type: string

# Called by other workflows (e.g. build.yaml)
workflow_call:
inputs:
version:
description: Version of HAOS to build index for
required: true
type: string

env:
PYTHON_VERSION: "3.10"

jobs:
build-index:
name: Build Home Assistant OS artifacts index
runs-on: ubuntu-22.04
steps:
- name: Setup Python version ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install AWS CLI
run: pip install awscli

- name: Create build index
env:
AWS_ACCESS_KEY_ID: ${{ secrets.R2_OS_ARTIFACTS_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_OS_ARTIFACTS_KEY }}
run: |
aws s3api list-objects-v2 \
--bucket "${{ secrets.R2_OS_ARTIFACTS_BUCKET }}" \
--endpoint-url "${{ secrets.R2_OS_ARTIFACTS_ENDPOINT }}" \
--prefix "${{ github.event.inputs.version }}/" \
--query 'Contents[].Key' | jq 'map(split("/")[1]) | sort' > "${{ github.event.inputs.version }}.json"
aws s3 cp \
"${{ github.event.inputs.version }}.json" \
s3://${{ secrets.R2_OS_ARTIFACTS_BUCKET }}/indexes/ \
--endpoint-url "${{ secrets.R2_OS_ARTIFACTS_ENDPOINT }}""
- name: Regenerate artifacts index
env:
AWS_ACCESS_KEY_ID: ${{ secrets.R2_OS_ARTIFACTS_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_OS_ARTIFACTS_KEY }}
run: |
aws s3api list-objects-v2 \
--bucket "${{ secrets.R2_OS_ARTIFACTS_BUCKET }}" \
--endpoint-url "${{ secrets.R2_OS_ARTIFACTS_ENDPOINT }}" \
--prefix "indexes/" \
--query 'Contents[].Key' | jq 'map(capture("indexes/(?<version>[[:digit:]].+).json").version) | sort' > .os-artifacts/index.json
aws s3 sync \
.os-artifacts/ \
s3://${{ secrets.R2_OS_ARTIFACTS_BUCKET }}/ \
--endpoint-url "${{ secrets.R2_OS_ARTIFACTS_ENDPOINT }}" \
- name: Flush CloudFlare cache
run: |
curl --silent --show-error --fail -X POST \
"https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE }}/purge_cache" \
-H "Authorization: Bearer ${{ secrets.CF_PURGE_TOKEN }}" \
-H "Content-Type: application/json" \
--data '{"files": [
"https://os-artifacts.home-assistant.io/index.html",
"https://os-artifacts.home-assistant.io/index.json"
] }'
51 changes: 8 additions & 43 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,6 @@ jobs:
--include "haos_*" \
--endpoint-url ${{ secrets.R2_OS_ARTIFACTS_ENDPOINT }}
ls haos_* | jq --raw-input | jq --slurp > "${{ needs.prepare.outputs.version_full }}.json"
aws s3 cp \
"${{ needs.prepare.outputs.version_full }}.json" \
s3://${{ secrets.R2_OS_ARTIFACTS_BUCKET }}/indexes/ \
--endpoint-url ${{ secrets.R2_OS_ARTIFACTS_ENDPOINT }}
- name: Upload release assets
if: ${{ github.event_name == 'release' }}
uses: shogo82148/actions-upload-release-asset@v1
Expand Down Expand Up @@ -247,6 +241,14 @@ jobs:
needs: [ build, prepare ]
uses: ./.github/workflows/test.yaml

update_index:
name: Update artifacts index
if: ${{ github.event_name != 'release' }}
needs: [ build, prepare ]
uses: home-assistant/operating-system/.github/workflows/artifacts-index.yaml@dev
with:
version: ${{ needs.prepare.outputs.version_full }}

bump_version:
name: Bump ${{ needs.prepare.outputs.channel }} channel version
if: ${{ github.repository == 'home-assistant/operating-system' }}
Expand All @@ -267,43 +269,6 @@ jobs:
email: ${{ secrets.GIT_EMAIL }}
token: ${{ secrets.GIT_TOKEN }}

- name: Setup Python version ${{ env.PYTHON_VERSION }}
if: ${{ github.event_name != 'release' }}
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install AWS CLI
if: ${{ github.event_name != 'release' }}
run: pip install awscli

- name: Regenerate artifacts index
if: ${{ github.event_name != 'release' }}
env:
AWS_ACCESS_KEY_ID: ${{ secrets.R2_OS_ARTIFACTS_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_OS_ARTIFACTS_KEY }}
run: |
aws s3api list-objects-v2 \
--bucket "${{ secrets.R2_OS_ARTIFACTS_BUCKET }}" \
--endpoint-url "${{ secrets.R2_OS_ARTIFACTS_ENDPOINT }}" \
--prefix "indexes/" \
--query 'Contents[].Key' | jq 'map(capture("indexes/(?<version>[[:digit:]].+).json").version) | sort' > .os-artifacts/index.json
aws s3 sync \
.os-artifacts/ \
s3://${{ secrets.R2_OS_ARTIFACTS_BUCKET }}/ \
--endpoint-url ${{ secrets.R2_OS_ARTIFACTS_ENDPOINT }}
- name: Flush CloudFlare cache
run: |
curl --silent --show-error --fail -X POST \
"https://api.cloudflare.com/client/v4/zones/${{ secrets.CF_ZONE }}/purge_cache" \
-H "Authorization: Bearer ${{ secrets.CF_PURGE_TOKEN }}" \
-H "Content-Type: application/json" \
--data '{"files": [
"https://os-artifacts.home-assistant.io/index.html",
"https://os-artifacts.home-assistant.io/index.json"
] }'
- name: Bump Home Assistant OS ${{ needs.prepare.outputs.channel }} channel version
uses: home-assistant/actions/helpers/version-push@master
with:
Expand Down

0 comments on commit 2e8b66d

Please sign in to comment.