|
| 1 | +# Copyright 2026 The Fuchsia Authors |
| 2 | +# |
| 3 | +# Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 |
| 4 | +# <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT |
| 5 | +# license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. |
| 6 | +# This file may not be copied, modified, or distributed except according to |
| 7 | +# those terms. |
| 8 | + |
| 9 | +name: Store validated reverse-before blobs |
| 10 | + |
| 11 | +'on': |
| 12 | + push: |
| 13 | + branches: [fix-transmute-reverse-before] |
| 14 | + paths: [.github/workflows/reverse-before-publish.yml] |
| 15 | + |
| 16 | +permissions: {} |
| 17 | + |
| 18 | +jobs: |
| 19 | + publish-blobs: |
| 20 | + if: github.repository == 'google/zerocopy' && github.ref == 'refs/heads/fix-transmute-reverse-before' |
| 21 | + runs-on: ubuntu-latest |
| 22 | + timeout-minutes: 5 |
| 23 | + permissions: |
| 24 | + actions: read |
| 25 | + contents: write |
| 26 | + steps: |
| 27 | + - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 28 | + with: |
| 29 | + name: reverse-before-validation |
| 30 | + run-id: 35404943322 |
| 31 | + github-token: ${{ github.token }} |
| 32 | + path: ${{ runner.temp }}/validated |
| 33 | + - name: Store hash-verified source as Git blobs |
| 34 | + env: |
| 35 | + GH_TOKEN: ${{ github.token }} |
| 36 | + shell: python |
| 37 | + run: | |
| 38 | + import base64, hashlib, json, os, tarfile, urllib.request |
| 39 | + from pathlib import Path |
| 40 | + assert os.environ['GITHUB_REPOSITORY'] == 'google/zerocopy' |
| 41 | + assert os.environ['GITHUB_REF'] == 'refs/heads/fix-transmute-reverse-before' |
| 42 | + expected = { |
| 43 | + "zerocopy/src/impls.rs": "b1d513e772673b6687b22b1cbd2be0a7ee18fc6d", |
| 44 | + "zerocopy/src/layout.rs": "20f4a6ab21a4ca8d4e794df5eb92255ba1e86b57", |
| 45 | + "zerocopy/src/lib.rs": "41f66e569fe3f8b88ed1a96c0da5998f64aa040d", |
| 46 | + "zerocopy/src/pointer/invariant.rs": "3de2b6fac594ef714493289e205df60b02777e12", |
| 47 | + "zerocopy/src/pointer/mod.rs": "e25c52fb8a3e22353149dbb883114fa221871edf", |
| 48 | + "zerocopy/src/pointer/ptr.rs": "f9f681c73046a942c9f142cb7f4f1289a8aba32b", |
| 49 | + "zerocopy/src/pointer/transmute.rs": "1539581380a1d8da095b8e8e273645134d306867", |
| 50 | + "zerocopy/src/pointer/transmute/reverse_tests.rs": "b10db1d9e93fe619d3867f33b5c7a36335f37357", |
| 51 | + "zerocopy/src/ref.rs": "8500f72b0f0be9d52caed2a9034ea73560536dfa", |
| 52 | + "zerocopy/src/util/macros.rs": "b547b2c1cc09e42d7d7f109dc347cb1dfe246d60", |
| 53 | + "zerocopy/src/wrappers.rs": "4b4943f917b7f7f90b486423595b4de24d251018", |
| 54 | + "zerocopy/zerocopy-derive/src/derive/project.rs": "a219489d87e5098fcc0c156212fd8994e4b9b860" |
| 55 | + } |
| 56 | + root = Path(os.environ['RUNNER_TEMP']) / 'validated' |
| 57 | + assert (root/'development-head.txt').read_text().strip() == 'df85e4328816073118ae226f6e16807ff553995e' |
| 58 | + statuses = dict(line.split() for line in (root/'status.txt').read_text().splitlines()) |
| 59 | + assert statuses and all(value == '0' for value in statuses.values()), statuses |
| 60 | + with tarfile.open(root/'source.tar') as archive: |
| 61 | + members = archive.getmembers() |
| 62 | + assert len(members) == len(expected) |
| 63 | + assert {m.name for m in members} == set(expected) |
| 64 | + assert all(m.isfile() and m.size < 2_000_000 for m in members) |
| 65 | + data = {m.name: archive.extractfile(m).read() for m in members} |
| 66 | + # Verify every input before making the first write; never execute artifact code. |
| 67 | + for path, content in data.items(): |
| 68 | + content.decode('utf-8') |
| 69 | + sha = hashlib.sha1(f'blob {len(content)}\0'.encode() + content).hexdigest() |
| 70 | + assert sha == expected[path], path |
| 71 | + for path, content in sorted(data.items()): |
| 72 | + request = urllib.request.Request( |
| 73 | + 'https://api.github.com/repos/google/zerocopy/git/blobs', |
| 74 | + data=json.dumps({'encoding': 'base64', 'content': base64.b64encode(content).decode()}).encode(), |
| 75 | + headers={'Authorization': 'Bearer ' + os.environ['GH_TOKEN'], |
| 76 | + 'Accept': 'application/vnd.github+json', |
| 77 | + 'X-GitHub-Api-Version': '2022-11-28', |
| 78 | + 'Content-Type': 'application/json'}, |
| 79 | + method='POST') |
| 80 | + with urllib.request.urlopen(request, timeout=60) as response: |
| 81 | + stored = json.load(response) |
| 82 | + assert stored['sha'] == expected[path], path |
| 83 | + print(json.dumps({'path': path, 'sha': stored['sha']}), flush=True) |
| 84 | + print('Stored exactly the 12 validated source blobs; no ref or branch was changed.') |
0 commit comments