Skip to content

Commit 529572f

Browse files
authored
Merge pull request #183 from firebase/feature/js-save-package-hash
Add hash for generated C++ SDK package so we can verify the file later.
2 parents 5f32e93 + 7ba7516 commit 529572f

File tree

1 file changed

+113
-16
lines changed

1 file changed

+113
-16
lines changed

.github/workflows/cpp-packaging.yml

Lines changed: 113 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,32 @@ env:
1818
binutilsVer: 2.35.1
1919
# Demumble 1.1.0 released Nov 13, 2018
2020
demumbleVer: 1.1.0
21+
# Use SHA256 for hashing files.
22+
hashCommand: sha256sum
2123

2224
jobs:
25+
log_inputs:
26+
name: log-inputs
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: log run inputs
30+
run: |
31+
if [[ -n "${{ github.event.inputs.downloadPublicVersion }}" ]]; then
32+
echo "::warning ::Downloading public SDK package from https://dl.google.com/firebase/sdk/cpp/firebase_cpp_sdk_${{ github.event.inputs.downloadPublicVersion }}.zip"
33+
elif [[ -n "${{ github.event.inputs.downloadPreviousRun }}" ]]; then
34+
echo "::warning ::Downloading SDK package from previous run at https://github.com/firebase/firebase-cpp-sdk/actions/runs/${{ github.event.inputs.downloadPreviousRun }}"
35+
fi
36+
if [[ -n "${{ github.event.inputs.commitIdToPackage }}" ]]; then
37+
if [[ -n "${{ github.event.inputs.downloadPublicVersion }}" || -n "${{ github.event.inputs.downloadPreviousRun }}" ]]; then
38+
echo "::warning ::Using commit ID '${{ github.event.inputs.commitIdToPackage }}' for building tests."
39+
else
40+
echo "::warning ::Using commit ID '${{ github.event.inputs.commitIdToPackage }}' for building and packaging SDK and tests."
41+
fi
42+
fi
43+
if [[ "${{ github.event.inputs.preserveIntermediateArtifacts }}" != "0" ]]; then
44+
echo "::warning ::Intermediate artifacts will be preserved."
45+
fi
46+
2347
build_tools:
2448
name: build-tools-${{ matrix.tools_platform }}
2549
runs-on: ${{ matrix.os }}
@@ -54,12 +78,14 @@ jobs:
5478
cd -
5579
mkdir -p packaging-tools
5680
cp -af /tmp/binutils/bin/* packaging-tools
81+
5782
- name: fetch demumble
5883
uses: actions/[email protected]
5984
with:
6085
repository: nico/demumble
6186
path: demumble-src
6287
ref: v${{ env.demumbleVer }}
88+
6389
- name: build demumble
6490
run: |
6591
cd demumble-src
@@ -69,11 +95,13 @@ jobs:
6995
cd -
7096
mkdir -p packaging-tools-
7197
cp -af demumble-src/demumble packaging-tools
98+
7299
- name: archive tools
73100
run: |
74101
cd packaging-tools
75102
ls
76103
tar -czhf ../packaging-tools.tgz .
104+
77105
- name: upload artifacts
78106
uses: actions/upload-artifact@v2
79107
with:
@@ -90,14 +118,17 @@ jobs:
90118
with:
91119
path: sdk-src
92120
ref: ${{ github.event.inputs.commitIdToPackage }}
121+
93122
- name: install prerequisites
94123
run: sdk-src/build_scripts/ios/install_prereqs.sh
124+
95125
- name: build sdk
96126
run: |
97127
sdk-src/build_scripts/ios/build.sh -b firebase-cpp-sdk-ios-build -s sdk-src
98128
sdk-src/build_scripts/ios/package.sh firebase-cpp-sdk-ios-build firebase-cpp-sdk-ios-package
99129
cd firebase-cpp-sdk-ios-package
100130
tar -czhf ../firebase-cpp-sdk-ios-package.tgz .
131+
101132
- name: Print built libraries
102133
shell: bash
103134
run: |
@@ -107,10 +138,12 @@ jobs:
107138
find firebase-cpp-sdk-*-build -name "*.a"
108139
find firebase-cpp-sdk-*-build -name "*.so"
109140
find firebase-cpp-sdk-*-build -name "*.framework"
141+
110142
- name: Print package contents
111143
shell: bash
112144
run: |
113145
find firebase-cpp-sdk-*-package -type f
146+
114147
- name: upload artifacts
115148
uses: actions/upload-artifact@v2
116149
with:
@@ -131,14 +164,17 @@ jobs:
131164
with:
132165
path: sdk-src
133166
ref: ${{ github.event.inputs.commitIdToPackage }}
167+
134168
- name: install prerequisites
135169
run: sdk-src/build_scripts/android/install_prereqs.sh
170+
136171
- name: build sdk
137172
run: |
138173
sdk-src/build_scripts/android/build.sh firebase-cpp-sdk-android-${{ matrix.stl }}-build sdk-src ${{ matrix.stl }}
139174
sdk-src/build_scripts/android/package.sh firebase-cpp-sdk-android-${{ matrix.stl }}-build firebase-cpp-sdk-android-${{ matrix.stl }}-package ${{ matrix.stl }}
140175
cd firebase-cpp-sdk-android-${{ matrix.stl }}-package
141176
tar -czhf ../firebase-cpp-sdk-android-${{ matrix.stl}}-package.tgz .
177+
142178
- name: Print built libraries
143179
shell: bash
144180
run: |
@@ -148,10 +184,12 @@ jobs:
148184
find firebase-cpp-sdk-*-build -name "*.a"
149185
find firebase-cpp-sdk-*-build -name "*.so"
150186
find firebase-cpp-sdk-*-build -name "*.framework"
187+
151188
- name: Print package contents
152189
shell: bash
153190
run: |
154191
find firebase-cpp-sdk-*-package -type f
192+
155193
- name: upload artifacts
156194
uses: actions/upload-artifact@v2
157195
with:
@@ -327,21 +365,25 @@ jobs:
327365
with:
328366
path: sdk-src
329367
ref: ${{ github.event.inputs.commitIdToPackage }}
368+
330369
- name: download artifact
331370
uses: actions/download-artifact@v2
332371
with:
333372
# download-artifact doesn't support wildcards, but by default
334373
# will download all artifacts. Sadly this is what we must do.
335374
path: artifacts
375+
336376
- name: Setup python
337377
uses: actions/setup-python@v2
338378
with:
339379
python-version: 3.7
380+
340381
- name: Install prerequisites
341382
run: |
342383
cd sdk-src
343384
python scripts/gha/install_prereqs_desktop.py
344385
cd ..
386+
345387
- name: postprocess and package built SDK
346388
run: |
347389
mkdir -p bin
@@ -365,11 +407,13 @@ jobs:
365407
fi
366408
cd firebase-cpp-sdk-${{ matrix.sdk_platform }}${{ matrix.suffix }}-package
367409
tar -czhf ../firebase-cpp-sdk-${{ matrix.sdk_platform }}${{ matrix.suffix }}-package.tgz .
410+
368411
- name: Print package contents
369412
shell: bash
370413
run: |
371414
find firebase-cpp-sdk-*-package -type f
372-
- name: upload artifacts
415+
416+
- name: upload SDK zip
373417
uses: actions/upload-artifact@v2
374418
with:
375419
name: firebase-cpp-sdk-${{ matrix.sdk_platform }}${{ matrix.suffix}}-package
@@ -378,14 +422,14 @@ jobs:
378422
download_sdk_package:
379423
name: download-sdk-package
380424
runs-on: ubuntu-latest
425+
needs: [log_inputs]
381426
if: ${{ github.event.inputs.downloadPublicVersion != '' || github.event.inputs.downloadPreviousRun != '' }}
382427
steps:
383428
- name: fetch artifact from previous run
384429
uses: dawidd6/action-download-artifact@v2
385430
if: ${{ github.event.inputs.downloadPreviousRun != '' }}
386431
with:
387-
name: 'firebase_cpp_sdk'
388-
path: 'firebase-cpp-sdk-final'
432+
name: 'firebase_cpp_sdk.zip'
389433
workflow: 'cpp-packaging.yml'
390434
run_id: ${{ github.event.inputs.downloadPreviousRun }}
391435

@@ -396,7 +440,6 @@ jobs:
396440
echo Invalid version number: "${{ github.event.inputs.downloadPublicVersion }}"
397441
exit 1
398442
fi
399-
mkdir firebase-cpp-sdk-final
400443
set +e
401444
# Retry up to 10 times because Curl has a tendency to timeout on
402445
# Github runners.
@@ -406,19 +449,30 @@ jobs:
406449
sleep 300
407450
done
408451
set -e
409-
cd firebase-cpp-sdk-final
410-
unzip ../firebase_cpp_sdk.zip
411-
- name: upload artifacts
452+
453+
- name: compute SDK hash
454+
shell: bash
455+
run: |
456+
${{ env.hashCommand }} --tag firebase_cpp_sdk.zip > firebase_cpp_sdk_hash.txt
457+
echo "::warning ::$(cat firebase_cpp_sdk_hash.txt)"
458+
459+
- name: upload hash
460+
uses: actions/upload-artifact@v2
461+
with:
462+
name: firebase_cpp_sdk_hash.txt
463+
path: firebase_cpp_sdk_hash.txt
464+
465+
- name: upload SDK zip
412466
uses: actions/upload-artifact@v2
413467
with:
414-
name: firebase_cpp_sdk
415-
path: firebase-cpp-sdk-final
468+
name: firebase_cpp_sdk.zip
469+
path: firebase_cpp_sdk.zip
416470

417471
merge_packages:
418472
name: final-merge-packages
419473
runs-on: ubuntu-latest
420474
if: ${{ github.event.inputs.downloadPublicVersion == '' && github.event.inputs.downloadPreviousRun == '' }}
421-
needs: [build_and_package_ios, build_and_package_android, package_desktop]
475+
needs: [build_and_package_ios, build_and_package_android, package_desktop, log_inputs]
422476
steps:
423477
- name: fetch SDK
424478
uses: actions/[email protected]
@@ -434,6 +488,7 @@ jobs:
434488
path: artifacts
435489

436490
- name: merge SDK packages
491+
shell: bash
437492
run: |
438493
set -ex
439494
mkdir -p firebase-cpp-sdk-final/firebase_cpp_sdk
@@ -442,16 +497,39 @@ jobs:
442497
done
443498
# Add the final files.
444499
sdk-src/build_scripts/other/package.sh sdk-src firebase-cpp-sdk-final/firebase_cpp_sdk
500+
501+
# Zip up the package and grab a hash of the result.
502+
cd firebase-cpp-sdk-final
503+
# Save the hash of every file into the SDK package.
504+
find firebase_cpp_sdk -type f -print0 | xargs -0 ${{ env.hashCommand }} --tag > file_hashes.txt
505+
mv file_hashes.txt firebase_cpp_sdk/
506+
# Zip up the SDK package recursively, preserving symlinks.
507+
zip -9 -r -y ../firebase_cpp_sdk.zip firebase_cpp_sdk
508+
cd ..
509+
510+
- name: compute SDK hash
511+
shell: bash
512+
run: |
513+
${{ env.hashCommand }} --tag firebase_cpp_sdk.zip > firebase_cpp_sdk_hash.txt
514+
echo "::warning ::$(cat firebase_cpp_sdk_hash.txt)"
515+
445516
- name: Print final package contents
446517
shell: bash
447518
run: |
448519
cd firebase-cpp-sdk-final
449-
find * -type f
450-
- name: upload artifacts
520+
find firebase_cpp_sdk -type f
521+
522+
- name: upload hash
523+
uses: actions/upload-artifact@v2
524+
with:
525+
name: firebase_cpp_sdk_hash.txt
526+
path: firebase_cpp_sdk_hash.txt
527+
528+
- name: upload SDK zip
451529
uses: actions/upload-artifact@v2
452530
with:
453-
name: firebase_cpp_sdk
454-
path: firebase-cpp-sdk-final
531+
name: firebase_cpp_sdk.zip
532+
path: firebase_cpp_sdk.zip
455533

456534
cleanup_artifacts:
457535
# Clean up intermediate artifacts.
@@ -498,14 +576,33 @@ jobs:
498576
if: always()
499577
runs-on: ubuntu-latest
500578
steps:
501-
- name: download artifact
579+
- name: download SDK zip
502580
uses: actions/download-artifact@v2
503581
with:
504-
name: firebase_cpp_sdk
582+
name: firebase_cpp_sdk.zip
505583
path: .
584+
585+
- name: download hash
586+
uses: actions/download-artifact@v2
587+
with:
588+
name: firebase_cpp_sdk_hash.txt
589+
path: .
590+
506591
- name: List binary SDK files.
507592
run: |
593+
# Verify zipfile hash first.
594+
${{ env.hashCommand }} -c --quiet firebase_cpp_sdk_hash.txt
595+
unzip -q firebase_cpp_sdk.zip
508596
find . -print
597+
598+
- name: Verify SDK package files.
599+
run: |
600+
if [[ -r firebase_cpp_sdk/file_hashes.txt ]]; then
601+
${{ env.hashCommand }} -c --quiet firebase_cpp_sdk/file_hashes.txt
602+
else
603+
echo "::warning ::SDK package does not contain file_hashes.txt, cannot verify files in package."
604+
fi
605+
509606
- name: fetch integration test source
510607
uses: actions/[email protected]
511608
with:

0 commit comments

Comments
 (0)