diff --git a/.github/workflows/examples-published.yml b/.github/workflows/examples-published.yml index 476f00a3..29ce434f 100644 --- a/.github/workflows/examples-published.yml +++ b/.github/workflows/examples-published.yml @@ -97,13 +97,13 @@ jobs: with: python-version: '3.14' - # The free data files, from the assets common-ci fetches and keeps in - # the Actions cache for the day, so nothing follows the links here. - - name: Fetch the free data files + # The free data files, from the one shared copy that common-ci's + # Nightly Shared Assets workflow downloads each day, so nothing follows + # the links here. + - name: Restore the free data files if: steps.keys.outputs.run == 'true' uses: 51Degrees/common-ci/actions/fetch-assets@main with: - cache: 'true' assets: | 51Degrees-LiteV4.1.hash 20000 Evidence Records.yml @@ -111,15 +111,14 @@ jobs: 51Degrees-LiteIpiV41.ipi # The Device Detection tests of the data file update example serve a - # copy of the TAC data file. It comes from the Distributor with the - # data license, which common-ci's fetch reads as - # _51DEGREES_LICENSE_KEY and fails without. The file is licensed, so - # it is not kept in the Actions cache. - - name: Fetch the TAC data file + # copy of the TAC data file. It comes from the same shared copy, + # decrypted with CACHE_ENCRYPTION_KEY, which common-ci's step reads + # from this step's environment. Nothing here keeps it. + - name: Restore the TAC data file if: steps.keys.outputs.run == 'true' uses: 51Degrees/common-ci/actions/fetch-assets@main env: - _51DEGREES_LICENSE_KEY: ${{ secrets.LICENSE_KEY_V4TAC_IPIV4ENTERPRISE }} + CACHE_ENCRYPTION_KEY: ${{ secrets.CACHE_ENCRYPTION_KEY }} with: assets: TAC-HashV41.hash diff --git a/.github/workflows/free-threaded-python.yml b/.github/workflows/free-threaded-python.yml index 6125a1e4..8c328e92 100644 --- a/.github/workflows/free-threaded-python.yml +++ b/.github/workflows/free-threaded-python.yml @@ -2,11 +2,10 @@ name: Free-threaded Python # Builds the Device Detection and IP Intelligence on-premise packages on the # free-threaded builds of Python and runs their tests there, with the free -# Lite data files. Those come from the assets common-ci fetches for each run, -# as every other workflow's tests do. The first job finds them in the asset -# cache, or fetches them into it with common-ci's prefetch_assets action when -# it misses, and the test jobs restore them from there. No job downloads -# them from the links in the data submodule. +# Lite data files. Those come from the one shared copy that common-ci's +# Nightly Shared Assets workflow downloads each day, as every other +# workflow's tests do, restored by common-ci's fetch-assets action. No job +# downloads them from the links in the data submodule. # ci/free-threaded-python.Tests.ps1 checks this. The native modules do not declare that they run without # the GIL, so Python turns the GIL back on when it loads them. # tests/test_free_threaded.py in each package checks that it does, and is @@ -45,55 +44,8 @@ env: _51DEGREES_WARNINGS_AS_ERRORS: 'true' jobs: - # The job is named Configure, as common-ci's is, because this repository's - # ci/fetch-assets.ps1 fetches the assets of every product only in a job of - # that name. The asset cache it fills is the one the other workflows that - # day restore, so it must never hold only some of them. - Configure: - name: Find or fetch the run's assets - runs-on: ubuntu-latest - outputs: - key: ${{ steps.prefetch-assets.outputs.cache-key }} - defaults: - run: - shell: pwsh - steps: - # common-ci's action and steps run from its checkout, with this - # repository below it, as in common-ci's own workflows. - - name: Checkout common-ci - uses: actions/checkout@v4 - with: - repository: 51Degrees/common-ci - ref: main - persist-credentials: false - - # The fetch links the assets into the data submodule, so it is - # checked out too. - - name: Checkout repository - uses: actions/checkout@v4 - with: - path: ${{ github.event.repository.name }} - persist-credentials: false - submodules: recursive - - # Restores nothing, and fetches the assets into the cache only when it - # has no copy under the day's key. - # The action is handed no secrets, because GitHub marks a workflow that - # hands every secret to a step as possibly malicious and holds each run - # for approval. The fetch reads only the data file license key, which - # goes as license-key. - - name: Find or fetch the assets - id: prefetch-assets - uses: ./.github/actions/prefetch_assets - with: - repo: ${{ github.event.repository.name }} - secrets: '{}' - vars: ${{ toJSON(vars) }} - license-key: ${{ secrets.LICENSE_KEY_V4TAC_IPIV4ENTERPRISE }} - free-threaded: name: Python ${{ matrix.python }} on ${{ matrix.os }} - needs: Configure strategy: fail-fast: false matrix: @@ -167,17 +119,16 @@ jobs: -e device-detection/fiftyone_devicedetection ` -e device-detection/fiftyone_devicedetection_examples - # The path and the cross-OS setting are those prefetch_assets saves - # with, so the key matches. - - name: Restore the run's assets - uses: actions/cache/restore@v5 + # The free files need no key. A file the shared copy lacks fails the + # step, and nothing downloads it here. + - name: Restore the free data files + uses: 51Degrees/common-ci/actions/fetch-assets@main with: - path: assets - key: ${{ needs.Configure.outputs.key }} - enableCrossOsArchive: true - # The first job fetched them, so a miss is a fault, never a reason - # to download them here. - fail-on-cache-miss: true + assets: | + 51Degrees-LiteV4.1.hash + 20000 Evidence Records.yml + 51Degrees-IPIV4AsnIpiV41.ipi + 51Degrees-LiteIpiV41.ipi # Copies, not links, so the Windows job needs no right to make links. - name: Put the free data files where the tests look for them diff --git a/ci/check-environment-variable-names.ps1 b/ci/check-environment-variable-names.ps1 index e3f4edbc..694469ce 100644 --- a/ci/check-environment-variable-names.ps1 +++ b/ci/check-environment-variable-names.ps1 @@ -35,8 +35,10 @@ $script:PlatformNames = @( $script:PlatformPrefixes = @('GITHUB_') # The names only CI uses. No customer sets them, so they have no _51DEGREES_ -# prefix, and each name says what it holds. -$script:CiNames = @('CLOUD_STAGING_ENDPOINT', 'RESOURCE_KEY_BESPOKE_STAGING') +# prefix, and each name says what it holds. CACHE_ENCRYPTION_KEY decrypts the +# licensed files of common-ci's shared copy of the data files, and a workflow +# gives it to common-ci's fetch-assets step in that step's environment. +$script:CiNames = @('CACHE_ENCRYPTION_KEY', 'CLOUD_STAGING_ENDPOINT', 'RESOURCE_KEY_BESPOKE_STAGING') $name = '(?[A-Za-z0-9_]+)' $quoted = "['`"]$name['`"]" diff --git a/ci/free-threaded-python.Tests.ps1 b/ci/free-threaded-python.Tests.ps1 index 848a3aa3..86d14b27 100644 --- a/ci/free-threaded-python.Tests.ps1 +++ b/ci/free-threaded-python.Tests.ps1 @@ -1,7 +1,8 @@ # Tests that .github/workflows/free-threaded-python.yml takes the free Lite -# data files from the assets common-ci fetches for each run, in one job, and -# that the jobs that test restore them from that job's cache, rather than any -# job downloading them from the links in the data submodule. +# data files from the one shared copy that common-ci's Nightly Shared Assets +# workflow downloads each day, restored in each job that tests by common-ci's +# fetch-assets step, rather than any job downloading them from the links in +# the data submodule or keeping them in this repository's Actions cache. # The workflow is read as text, as the runners have no YAML module. BeforeAll { @@ -52,10 +53,10 @@ BeforeAll { } } - $script:Fetching = @($script:Jobs.Keys | Where-Object { - ($script:Jobs[$_] -join "`n") -match 'uses:\s*\S*prefetch_assets' }) $script:Testing = @($script:Jobs.Keys | Where-Object { ($script:Jobs[$_] -join "`n") -match 'pytest' }) + $script:FreeFiles = @('51Degrees-LiteV4.1.hash', '20000 Evidence Records.yml', + '51Degrees-IPIV4AsnIpiV41.ipi', '51Degrees-LiteIpiV41.ipi') } Describe 'free-threaded-python.yml' { @@ -63,73 +64,32 @@ Describe 'free-threaded-python.yml' { $script:Text | Should -Not -Match 'get-data-files' } - It 'finds or fetches the assets in one job only' { - $script:Fetching.Count | Should -Be 1 - } - - It 'names that job Configure, so every product''s assets are fetched' { - # ci/fetch-assets.ps1 fetches every product's assets only in a job of - # that name, and the cache it fills is shared with the other - # workflows. - $script:Fetching[0] | Should -BeExactly 'Configure' - Get-Content -Raw (Join-Path $PSScriptRoot 'fetch-assets.ps1') | - Should -Match "GITHUB_JOB\s+-eq\s+'Configure'" - } - - It 'fetches with common-ci''s action, run from common-ci''s checkout' { - $job = $script:Fetching[0] - $prefetch = @(Get-Step $job './.github/actions/prefetch_assets') - $prefetch.Count | Should -Be 1 - Get-Value $prefetch[0] 'id' | Should -Not -BeNullOrEmpty - Get-Value $prefetch[0] 'license-key' | Should -Not -BeNullOrEmpty - $checkouts = @(Get-Step $job 'actions/checkout') - @($checkouts | Where-Object { - (Get-Value $_ 'repository') -eq '51Degrees/common-ci' -and - -not (Get-Value $_ 'path') }).Count | Should -Be 1 - $own = @($checkouts | Where-Object { -not (Get-Value $_ 'repository') }) - $own.Count | Should -Be 1 - Get-Value $own[0] 'path' | Should -Be (Get-Value $prefetch[0] 'repo') - Get-Value $own[0] 'submodules' | Should -Be 'recursive' + It 'keeps nothing in the Actions cache and runs no prefetch' { + $script:Text | Should -Not -Match 'actions/cache|prefetch_assets' } It 'hands no step every secret, so GitHub does not hold its runs' { # GitHub holds each run of a workflow that hands every secret to a # step for approval, and the run never starts on its own. $script:Text | Should -Not -Match 'toJSON\(\s*secrets\s*\)' - $prefetch = @(Get-Step $script:Fetching[0] './.github/actions/prefetch_assets') - Get-Value $prefetch[0] 'secrets' | Should -BeExactly "'{}'" - } - - It 'gives the cache key to the jobs that test' { - $job = $script:Fetching[0] - $id = Get-Value (@(Get-Step $job './.github/actions/prefetch_assets')[0]) 'id' - ($script:Jobs[$job] -join "`n") | Should -Match ( - '\n outputs:\s*\n\s+key:\s*' + - [regex]::Escape('${{ steps.' + $id + '.outputs.cache-key }}')) } - It 'never fetches in a job that runs the tests' { + It 'restores the free files from the shared copy in each job that runs the tests' { $script:Testing.Count | Should -BeGreaterThan 0 - foreach ($job in $script:Testing) { - $script:Fetching | Should -Not -Contain $job - } - } - - It 'restores the assets in each job that runs the tests, as prefetch_assets saves them' { - $job = $script:Fetching[0] foreach ($testing in $script:Testing) { - $text = $script:Jobs[$testing] -join "`n" - $text | Should -Match "\n needs:\s*\[?\s*$([regex]::Escape($job))\b" - $restore = @(Get-Step $testing 'actions/cache/restore') + $restore = @(Get-Step $testing '51Degrees/common-ci/actions/fetch-assets') $restore.Count | Should -Be 1 - Get-Value $restore[0] 'path' | Should -Be 'assets' - Get-Value $restore[0] 'key' | - Should -Be ('${{ needs.' + $job + '.outputs.key }}') - Get-Value $restore[0] 'fail-on-cache-miss' | Should -Be 'true' - Get-Value $restore[0] 'enableCrossOsArchive' | Should -Be 'true' + $text = $restore[0] -join "`n" + foreach ($file in $script:FreeFiles) { + $text | Should -Match "(?m)^\s+$([regex]::Escape($file))\s*$" + } + # The free files need no key, and nothing is downloaded or kept. + $text | Should -Not -Match 'encryption-key|cache:|lazy:' + $jobText = $script:Jobs[$testing] -join "`n" + $jobText.IndexOf('common-ci/actions/fetch-assets') | + Should -BeLessThan $jobText.IndexOf('- name: Put the free data files where the tests look for them') } } - It 'puts each free data file the tests use in place from the assets' { foreach ($testing in $script:Testing) { $text = $script:Jobs[$testing] -join "`n"