Skip to content

Commit

Permalink
Merge pull request #285 from Shopify/minor-cleanups
Browse files Browse the repository at this point in the history
Make workflows consistent and stop using ls for finding files
  • Loading branch information
elsom25 authored Aug 20, 2024
2 parents 7b1d091 + 62ab02d commit 7622c8d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 12 deletions.
28 changes: 23 additions & 5 deletions .github/workflows/generate_dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ jobs:
# Create manifest and upload everything
- name: Create distribution manifest
run: |
find dist -type f -print0 | sort -z | xargs -0 b3sum > manifest.b3
echo -n "${{ secrets.MANIFEST_KEY }}" | b3sum --keyed manifest.b3 > manifest.b3.sig
target="dist"
manifest="manifest.b3"
manifest_sig="${manifest}.sig"
find "$target" -type f -print0 | sort -z | xargs -0 b3sum > "$manifest"
echo -n "${{ secrets.MANIFEST_KEY }}" | b3sum --keyed "$manifest" > "$manifest_sig"
- uses: actions/upload-artifact@v4
with:
name: dist
Expand Down Expand Up @@ -100,11 +104,25 @@ jobs:
sudo mv b3sum /usr/local/bin/
- name: Verify file integrity
run: |
echo -n "${{ secrets.MANIFEST_KEY }}" | b3sum --keyed manifest.b3 > verify.sig
if ! (cmp -s manifest.b3.sig verify.sig && b3sum dist --check manifest.b3); then
echo "Error: Integrity check failed. Manifest signature or file integrity mismatch."
manifest="manifest.b3"
manifest_sig="${manifest}.sig"
verify_sig="verify.b3.sig"
echo -n "${{ secrets.MANIFEST_KEY }}" | b3sum --keyed "$manifest" > "$verify_sig"
echo "Vetting $manifest_sig with generated $verify_sig"
if ! (cmp -s "$manifest_sig" "$verify_sig"); then
echo "Error: Integrity failure. Invalid key used to generate ${verify_sig}."
exit 1
fi
rm -f "$manifest_sig" "$verify_sig"
echo "Vetting $manifest"
if ! (b3sum --check "$manifest"); then
echo "Error: Integrity failure. Files are inconsistent with ${manifest}."
exit 1
fi
rm -f "$manifest"
- name: Commit distribution files
run: |
git config --local user.name "GitHub Action"
Expand Down
40 changes: 33 additions & 7 deletions .github/workflows/generate_dist_locales.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ jobs:
# Create manifest and upload everything
- name: Create distribution manifest
run: |
find dist/${{ matrix.locale }} -type f -print0 | sort -z | xargs -0 b3sum > ${{ matrix.locale }}_manifest.b3
echo -n "${{ secrets.MANIFEST_KEY }}" | b3sum --keyed ${{ matrix.locale }}_manifest.b3 > ${{ matrix.locale }}_manifest.b3.sig
target="dist/${{ matrix.locale }}"
manifest="${{ matrix.locale }}_manifest.b3"
manifest_sig="${manifest}.sig"
find "$target" -type f -print0 | sort -z | xargs -0 b3sum > "$manifest"
echo -n "${{ secrets.MANIFEST_KEY }}" | b3sum --keyed "$manifest" > "$manifest_sig"
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.locale }}
Expand Down Expand Up @@ -98,15 +102,37 @@ jobs:
sudo mv b3sum /usr/local/bin/
- name: Verify file integrity
run: |
for locale in $(ls -d dist/*/ | sed 's#dist/##' | sed 's#/##'); do
echo -n "${{ secrets.MANIFEST_KEY }}" | b3sum --keyed "${locale}_manifest.b3" > verify.sig
find dist -maxdepth 1 -mindepth 1 -type d | while read -r locale_path; do
locale=$(basename "$locale_path")
manifest="${locale}_manifest.b3"
manifest_sig="${manifest}.sig"
verify_sig="${locale}_verify.b3.sig"
echo -n "${{ secrets.MANIFEST_KEY }}" | b3sum --keyed "$manifest" > "$verify_sig"
if ! (cmp -s "${locale}_manifest.b3.sig" "verify.sig" && b3sum --check "${locale}_manifest.b3"); then
echo "Error: Integrity check failed for ${locale}. Manifest signature or file integrity mismatched."
echo "Vetting $manifest_sig with generated $verify_sig"
if ! (cmp -s "$manifest_sig" "$verify_sig"); then
echo "Error: Integrity failure for ${locale}. Invalid key used to generate ${verify_sig}."
exit 1
fi
rm -f "$manifest_sig" "$verify_sig"
echo "Vetting $manifest"
if ! (b3sum --check "$manifest"); then
echo "Error: Integrity failure for ${locale}. Files are inconsistent with ${manifest}."
exit 1
fi
rm -f "$manifest"
done
rm -f *.b3 *.sig
# Check for any remaining manifest files
unchecked_manifests=$(find . -maxdepth 1 -name '*_manifest.b3')
if [ -n "$unchecked_manifests" ]; then
echo "Error: Unchecked manifest files found:"
echo "$unchecked_manifests"
exit 1
fi
- name: Set up short SHA
id: short_sha
run: echo "sha=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ node_modules

# Ignore master key for decrypting credentials and more.
/config/master.key

# Ignore build manifests
*.b3
*.b3.sig

0 comments on commit 7622c8d

Please sign in to comment.