|
9 | 9 | run_id: |
10 | 10 | required: true |
11 | 11 | type: string |
| 12 | + secrets: |
| 13 | + AWS_ACCESS_KEY_ID: |
| 14 | + required: true |
| 15 | + AWS_SECRET_ACCESS_KEY: |
| 16 | + required: true |
| 17 | + DL_DISTRIBUTION_ID: |
| 18 | + required: true |
12 | 19 |
|
13 | 20 | workflow_dispatch: |
14 | 21 | inputs: |
|
22 | 29 | name: Build Offline Archives (${{ matrix.package_name }}) |
23 | 30 | runs-on: ${{ matrix.os }} |
24 | 31 | continue-on-error: true |
| 32 | + |
25 | 33 | strategy: |
26 | 34 | fail-fast: false |
27 | 35 | matrix: |
@@ -112,16 +120,119 @@ jobs: |
112 | 120 | path: offline_installer-${{ matrix.package_name }}-${{ env.VERSION }}.zip |
113 | 121 | retention-days: 30 |
114 | 122 |
|
115 | | - - name: Upload to release assets |
116 | | - if: github.event_name == 'release' |
117 | | - uses: actions/upload-release-asset@v1 |
| 123 | + # Release assets are limited to 2gb, until optimisation makes the archive less than 2gigs... |
| 124 | + # - name: Upload to release assets |
| 125 | + # if: github.event_name == 'release' |
| 126 | + # uses: actions/upload-release-asset@v1 |
| 127 | + # env: |
| 128 | + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 129 | + # with: |
| 130 | + # upload_url: ${{ github.event.release.upload_url }} |
| 131 | + # asset_path: offline_installer-${{ matrix.package_name }}-${{ env.VERSION }}.zip |
| 132 | + # asset_name: offline_installer-${{ matrix.package_name }}-${{ env.VERSION }}.zip |
| 133 | + # asset_content_type: application/zip |
| 134 | + |
| 135 | + - name: Upload installer to S3 |
| 136 | + env: |
| 137 | + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 138 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 139 | + AWS_DEFAULT_REGION: ap-east-1 |
| 140 | + VERSION: ${{ env.VERSION }} |
| 141 | + PACKAGE_NAME: ${{ matrix.package_name }} |
| 142 | + FILENAME: offline_installer-${{ matrix.package_name }}-${{ env.VERSION }}.zip |
| 143 | + shell: bash |
| 144 | + run: | |
| 145 | + # Only upload the installer ZIP |
| 146 | + aws s3 cp --acl=public-read "$FILENAME" "s3://espdldata/dl/eim/$FILENAME" |
| 147 | +
|
| 148 | + - name: Create build info file |
118 | 149 | env: |
119 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 150 | + VERSION: ${{ env.VERSION }} |
| 151 | + PACKAGE_NAME: ${{ matrix.package_name }} |
| 152 | + FILENAME: offline_installer-${{ matrix.package_name }}-${{ env.VERSION }}.zip |
| 153 | + shell: bash |
| 154 | + run: | |
| 155 | + # Create build info file |
| 156 | + jq -n \ |
| 157 | + --arg version "$VERSION" \ |
| 158 | + --arg platform "$PACKAGE_NAME" \ |
| 159 | + --arg filename "$FILENAME" \ |
| 160 | + '{"version": $version, "platform": $platform, "filename": $filename}' \ |
| 161 | + > build-info.json |
| 162 | +
|
| 163 | + - name: Save build info as artifact |
| 164 | + uses: actions/upload-artifact@v4 |
| 165 | + with: |
| 166 | + name: build-info-${{ matrix.package_name }} |
| 167 | + path: build-info.json |
| 168 | + |
| 169 | + update-json: |
| 170 | + needs: build-offline-archives |
| 171 | + runs-on: ubuntu-latest |
| 172 | + steps: |
| 173 | + - name: Download all build info artifacts |
| 174 | + uses: actions/download-artifact@v4 |
120 | 175 | with: |
121 | | - upload_url: ${{ github.event.release.upload_url }} |
122 | | - asset_path: offline_installer-${{ matrix.package_name }}-${{ env.VERSION }}.zip |
123 | | - asset_name: offline_installer-${{ matrix.package_name }}-${{ env.VERSION }}.zip |
124 | | - asset_content_type: application/zip |
| 176 | + pattern: build-info-* |
| 177 | + merge-multiple: true |
| 178 | + path: build-infos/ |
| 179 | + |
| 180 | + - name: Update offline_archives.json |
| 181 | + env: |
| 182 | + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 183 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 184 | + AWS_DEFAULT_REGION: ap-east-1 |
| 185 | + DL_DISTRIBUTION_ID: ${{ secrets.DL_DISTRIBUTION_ID }} |
| 186 | + VERSION: ${{ env.VERSION }} |
| 187 | + shell: bash |
| 188 | + run: | |
| 189 | + # Download existing JSON or create empty array |
| 190 | + if curl -f -s -o offline_archives.json http://dl.espressif.com/dl/eim/offline_archives.json; then |
| 191 | + echo "Downloaded existing offline_archives.json" |
| 192 | + if ! jq empty offline_archives.json 2>/dev/null; then |
| 193 | + echo "Downloaded JSON is invalid, creating new empty array" |
| 194 | + echo "[]" > offline_archives.json |
| 195 | + fi |
| 196 | + else |
| 197 | + echo "offline_archives.json does not exist, creating new empty array" |
| 198 | + echo "[]" > offline_archives.json |
| 199 | + fi |
| 200 | +
|
| 201 | + # Ensure valid JSON array |
| 202 | + if [ ! -s offline_archives.json ] || ! jq -e 'type == "array"' offline_archives.json >/dev/null 2>&1; then |
| 203 | + echo "File is empty or not a valid JSON array, initializing with empty array" |
| 204 | + echo "[]" > offline_archives.json |
| 205 | + fi |
| 206 | +
|
| 207 | + # Collect all new build info |
| 208 | + new_entries="[]" |
| 209 | + for build_info in build-infos/*.json; do |
| 210 | + if [ -f "$build_info" ]; then |
| 211 | + entry=$(cat "$build_info") |
| 212 | + new_entries=$(echo "$new_entries" | jq ". + [$entry]") |
| 213 | + fi |
| 214 | + done |
| 215 | +
|
| 216 | + # Remove existing entries with same filenames, then add all new entries |
| 217 | + updated_json=$(jq --argjson new_entries "$new_entries" ' |
| 218 | + . as $original | |
| 219 | + ($new_entries | map(.filename)) as $new_filenames | |
| 220 | + ($original | map(select(.filename as $f | $new_filenames | index($f) | not))) + $new_entries |
| 221 | + ' offline_archives.json) |
| 222 | +
|
| 223 | + echo "$updated_json" > updated_archives.json |
| 224 | +
|
| 225 | + # Verify the updated JSON is valid |
| 226 | + if ! jq empty updated_archives.json 2>/dev/null; then |
| 227 | + echo "Error: Generated JSON is invalid" |
| 228 | + exit 1 |
| 229 | + fi |
| 230 | +
|
| 231 | + # Upload updated JSON to S3 |
| 232 | + aws s3 cp --acl=public-read updated_archives.json s3://espdldata/dl/eim/offline_archives.json |
| 233 | +
|
| 234 | + # Invalidate Cache |
| 235 | + aws cloudfront create-invalidation --distribution-id ${DL_DISTRIBUTION_ID} --paths "/dl/eim/offline_archives.json" |
125 | 236 |
|
126 | 237 | Autotest-CLI-Offline: |
127 | 238 | needs: [build-offline-archives] |
|
0 commit comments