Skip to content

Commit

Permalink
Split r2 job into upload and promote (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesserockz authored Nov 18, 2024
1 parent 5a02c81 commit c0709c3
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 82 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/promote-r2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Promote firmware on Cloudflare R2

on:
workflow_call:
inputs:
version:
description: Version of the firmware to promote
required: true
type: string
directory:
description: Directory to promote the firmware to
required: true
type: string
channel:
description: Channel to upload to. "beta" or "production"
required: false
type: string
default: "production"
manifest-filename:
description: Filename of the manifest to write.
required: false
type: string
default: manifest.json

jobs:
promote:
name: Promote ${{ inputs.version }} to ${{ inputs.channel }}
runs-on: ubuntu-latest
environment: ${{ inputs.channel }}
steps:
- name: Download artifacts
uses: actions/[email protected]
with:
path: files

- name: Build ${{ inputs.manifest-filename }}
run: |
mkdir -p output
version="${{ inputs.version }}"
manifest_filename="${{ inputs.manifest-filename }}"
for device in files/*; do
device=$(basename $device)
mkdir -p output/$device
jq --arg version "$version" \
'.builds[].ota.path |= $version + "/" + . | (.builds[].parts // [])[].path |= $version + "/" + .' \
files/$device/$version/manifest.json > output/$device/$manifest_filename.json
done
- name: Upload ${{ inputs.manifest-filename }} to R2
uses: ryand56/[email protected]
with:
r2-account-id: ${{ secrets.CLOUDFLARE_R2_ACCOUNT_ID }}
r2-access-key-id: ${{ secrets.CLOUDFLARE_R2_ACCESS_KEY_ID }}
r2-secret-access-key: ${{ secrets.CLOUDFLARE_R2_SECRET_ACCESS_KEY }}
r2-bucket: ${{ secrets.CLOUDFLARE_R2_BUCKET }}
source-dir: output
destination-dir: ${{ inputs.directory }}/
84 changes: 2 additions & 82 deletions .github/workflows/upload-to-r2.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Upload
name: Upload firmware to Cloudflare R2
# This workflow is only to be used within the ESPHome organisation on GitHub.
# It is used to build and upload the binaries to Cloudflare R2 and only
# specific repositories will be granted the secrets required to do so.
Expand All @@ -10,20 +10,10 @@ on:
description: Directory to upload to
required: true
type: string
version:
description: Version of the release
required: false
type: string
default: ""
channel:
description: Channel to upload to. "beta" or "production"
required: false
type: string
default: "production"

jobs:
upload:
name: Upload firmware to Cloudflare R2
name: Upload
runs-on: ubuntu-latest
steps:
- name: Download artifacts
Expand All @@ -42,73 +32,3 @@ jobs:
r2-bucket: ${{ secrets.CLOUDFLARE_R2_BUCKET }}
source-dir: files
destination-dir: ${{ inputs.directory }}/

promote-prod:
name: Promote firmware to production
needs:
- upload
runs-on: ubuntu-latest
environment: production
if: inputs.version != '' && inputs.channel == 'production'
steps:
- name: Download artifacts
uses: actions/[email protected]
with:
path: files

- name: Copy manifest.json
run: |
mkdir -p output
version="${{ inputs.version }}"
for device in files/*; do
device=$(basename $device)
mkdir -p output/$device
jq --arg version "$version" \
'.builds[].ota.path |= $version + "/" + . | (.builds[].parts // [])[].path |= $version + "/" + .' \
files/$device/$version/manifest.json > output/$device/manifest.json
done
- name: Upload files to R2
uses: ryand56/[email protected]
with:
r2-account-id: ${{ secrets.CLOUDFLARE_R2_ACCOUNT_ID }}
r2-access-key-id: ${{ secrets.CLOUDFLARE_R2_ACCESS_KEY_ID }}
r2-secret-access-key: ${{ secrets.CLOUDFLARE_R2_SECRET_ACCESS_KEY }}
r2-bucket: ${{ secrets.CLOUDFLARE_R2_BUCKET }}
source-dir: output
destination-dir: ${{ inputs.directory }}/

promote-beta:
name: Promote firmware to beta
needs:
- upload
runs-on: ubuntu-latest
environment: beta
if: inputs.version != ''
steps:
- name: Download artifacts
uses: actions/[email protected]
with:
path: files

- name: Copy manifest.json
run: |
mkdir -p output
version="${{ inputs.version }}"
for device in files/*; do
device=$(basename $device)
mkdir -p output/$device
jq --arg version "$version" \
'.builds[].ota.path |= $version + "/" + . | (.builds[].parts // [])[].path |= $version + "/" + .' \
files/$device/$version/manifest.json > output/$device/manifest-beta.json
done
- name: Upload files to R2
uses: ryand56/[email protected]
with:
r2-account-id: ${{ secrets.CLOUDFLARE_R2_ACCOUNT_ID }}
r2-access-key-id: ${{ secrets.CLOUDFLARE_R2_ACCESS_KEY_ID }}
r2-secret-access-key: ${{ secrets.CLOUDFLARE_R2_SECRET_ACCESS_KEY }}
r2-bucket: ${{ secrets.CLOUDFLARE_R2_BUCKET }}
source-dir: output
destination-dir: ${{ inputs.directory }}/

0 comments on commit c0709c3

Please sign in to comment.