Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions .github/workflows/cloud-human-confidence.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: Cloud Human Confidence Tests

# Runs the Human Confidence web example's tests marked staging
# (pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/
# test_cloud_humanconfidence_web.py) against the staging cloud, because the
# production cloud does not serve HumanConfidenceSource yet. The Bespoke key
# must get the source Passive, and the Basic key no source.
#
# CLOUD_STAGING_ENDPOINT, the staging cloud's API base, is an organization
# variable, and RESOURCE_KEY_BESPOKE_STAGING, a Bespoke key the staging cloud
# knows, is an organization secret. Only this workflow uses them. common-ci
# passes on only _51DEGREES_ names and its own list of CI secrets, so in the
# shared integration tests the staging tests skip, and the other Human
# Confidence tests run there against the cloud _51DEGREES_CLOUD_ENDPOINT
# names. _51DEGREES_RESOURCE_KEY_BASIC is an organization secret that both
# clouds know.
#
# The run fails when a name is empty, and when a test skipped or none ran,
# because a cloud test that passes without calling the cloud has proved
# nothing. A pull request from a fork gets no secrets, so run this workflow
# from a branch in this repository.

on:
workflow_dispatch:
# Nightly as well, so a change in what the staging cloud answers is found
# the next morning.
schedule:
- cron: '50 6 * * *'
pull_request:
branches: [main, rc]
paths:
- 'pipeline/fiftyone_pipeline_cloudrequestengine/examples/src/fiftyone_pipeline_examples/cloud/humanconfidence_web/**'
- 'pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/conftest.py'
- 'pipeline/fiftyone_pipeline_cloudrequestengine/examples/tests/test_cloud_humanconfidence_web.py'
- '.github/workflows/cloud-human-confidence.yml'

permissions:
contents: read

jobs:
cloud-human-confidence:
name: Cloud Human Confidence
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
# The package versions written below come from the release tags.
fetch-depth: 0

# ci/write-package-versions.ps1 works out the versions with common-ci's
# release plan.
- name: Checkout common-ci
uses: actions/checkout@v4
with:
repository: 51Degrees/common-ci
ref: main
path: .common-ci
persist-credentials: false

- uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install the example and the packages it uses
env:
_51DEGREES_COMMON_CI_DIR: ${{ github.workspace }}/.common-ci
run: |
# A pip install that fails stops the step here, rather than
# leaving the tests to fail on a missing module.
$PSNativeCommandUseErrorActionPreference = $true
python -m pip install --upgrade pip pytest
# A package installed from this checkout is 0.0.0 without the
# version.txt this writes, which is below the versions the packages
# here require of each other, so pip would refuse them.
./ci/write-package-versions.ps1
python -m pip install `
-e pipeline/fiftyone_pipeline_core `
-e pipeline/fiftyone_pipeline_engines `
-e pipeline/fiftyone_pipeline_cloudrequestengine `
-e pipeline/fiftyone_pipeline_cloudrequestengine/examples

- name: Human Confidence tests against the staging cloud
working-directory: pipeline/fiftyone_pipeline_cloudrequestengine/examples
env:
CLOUD_STAGING_ENDPOINT: ${{ vars.CLOUD_STAGING_ENDPOINT }}
RESOURCE_KEY_BESPOKE_STAGING: ${{ secrets.RESOURCE_KEY_BESPOKE_STAGING }}
_51DEGREES_RESOURCE_KEY_BASIC: ${{ secrets._51DEGREES_RESOURCE_KEY_BASIC }}
run: |
# Each name, with where it comes from.
$names = [ordered]@{
CLOUD_STAGING_ENDPOINT = 'organization variable'
RESOURCE_KEY_BESPOKE_STAGING = 'organization secret'
_51DEGREES_RESOURCE_KEY_BASIC = 'organization secret'
}
$missing = $false
foreach ($name in $names.Keys) {
if (-not [Environment]::GetEnvironmentVariable($name)) {
Write-Host ("::error::$name is empty or missing. It comes " +
"from the $($names[$name]) of the same name.")
$missing = $true
}
}
if ($missing) { exit 1 }

$report = 'cloud-human-confidence.xml'
Remove-Item $report -ErrorAction SilentlyContinue
python -m pytest -m staging -p no:cacheprovider -v -rs `
"--junit-xml=$report"
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
if (-not (Test-Path $report)) {
Write-Host '::error::The staging tests did not run.'
exit 1
}
$suite = ([xml](Get-Content -Raw $report)).SelectSingleNode(
'//testsuite')
if ([int]$suite.tests -eq 0) {
Write-Host '::error::No staging test ran.'
exit 1
}
if ([int]$suite.skipped -gt 0) {
foreach ($skipped in $suite.SelectNodes('testcase[skipped]')) {
Write-Host ("::error::$($skipped.name) skipped, so it proved " +
"nothing. $($skipped.skipped.message)")
}
exit 1
}
23 changes: 18 additions & 5 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,28 @@ that GitHub, the operating system or a tool defines, such as `GITHUB_JOB` or
[`ci/check-environment-variable-names.ps1`](ci/check-environment-variable-names.ps1)
reads every tracked file and fails on a variable read or set under any other
name. It lists the platform names it lets through, so a new one is added
there.
there, and the names only CI uses, which have no prefix because no customer
sets them.

Two names are CI only. `CLOUD_STAGING_ENDPOINT`, an organization variable,
is the staging cloud's API base, ending `/api/v4/`, and
`RESOURCE_KEY_BESPOKE_STAGING`, an organization secret, is a Bespoke key the
staging cloud knows. Only
[`.github/workflows/cloud-human-confidence.yml`](.github/workflows/cloud-human-confidence.yml)
sets them, for the Human Confidence tests marked `staging`, which check what
the production cloud does not serve yet. common-ci passes on only
`_51DEGREES_` names and its own list of CI secrets, so in the shared
integration tests those tests skip. A staging test never falls back to
`_51DEGREES_CLOUD_ENDPOINT` or a default address.

`_51DEGREES_RESOURCE_KEY` is the name a person running a cloud example sets.
The tests that call the cloud service read `_51DEGREES_RESOURCE_KEY_BESPOKE`,
and a test of an example gives the example that key under
`_51DEGREES_RESOURCE_KEY`. The Basic Human Confidence test and the 51Did
tier test read `_51DEGREES_RESOURCE_KEY_BASIC`, an organization secret,
and skip naming it when it is not set. Cloud tests and examples call the service
`_51DEGREES_CLOUD_ENDPOINT` names, or the public one when it is not set.
`_51DEGREES_RESOURCE_KEY`. The Basic Human Confidence test, which calls the
staging cloud, and the 51Did tier test read `_51DEGREES_RESOURCE_KEY_BASIC`,
an organization secret, and skip naming it when it is not set. Cloud tests
and examples call the service `_51DEGREES_CLOUD_ENDPOINT` names, or the
public one when it is not set.

## Products keep their own CI scripts

Expand Down
11 changes: 11 additions & 0 deletions ci/check-environment-variable-names.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ Describe 'Find-EnvironmentNameProblem in a workflow' {

It 'leaves <Line> alone' -ForEach @(
@{ Line = ' _51DEGREES_EXAMPLE_SETTING: ${{ secrets._51DEGREES_EXAMPLE_SETTING }}' }
@{ Line = ' CLOUD_STAGING_ENDPOINT: ${{ vars.CLOUD_STAGING_ENDPOINT }}' }
@{ Line = ' RESOURCE_KEY_BESPOKE_STAGING: ${{ secrets.RESOURCE_KEY_BESPOKE_STAGING }}' }
@{ Line = ' GITHUB_TOKEN: ${{ github.token }}' }
@{ Line = ' uses: actions/checkout@v4' }
@{ Line = ' runs-on: ubuntu-latest' }
Expand All @@ -130,6 +132,9 @@ Describe 'Test-EnvironmentName' {
@{ Name = 'GITHUB_ENV' }
@{ Name = 'TEMP' }
@{ Name = 'PSModulePath' }
# Names only CI uses.
@{ Name = 'CLOUD_STAGING_ENDPOINT' }
@{ Name = 'RESOURCE_KEY_BESPOKE_STAGING' }
) {
Test-EnvironmentName $Name | Should -BeTrue
}
Expand All @@ -140,6 +145,12 @@ Describe 'Test-EnvironmentName' {
@{ Name = '51DEGREES_EXAMPLE_SETTING' }
@{ Name = 'TEMPORARY' }
@{ Name = 'MY_GITHUB_SETTING' }
# Look-alikes of the names only CI uses.
@{ Name = 'cloud_staging_endpoint' }
@{ Name = 'CLOUD_STAGING_ENDPOINT_URL' }
@{ Name = 'CLOUD_ENDPOINT' }
@{ Name = 'RESOURCE_KEY_BESPOKE' }
@{ Name = 'RESOURCE_KEY_BASIC_STAGING' }
) {
Test-EnvironmentName $Name | Should -BeFalse
}
Expand Down
21 changes: 15 additions & 6 deletions ci/check-environment-variable-names.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
# line that reads or sets an environment variable under another name.
#
# A name that GitHub, the operating system or a tool defines is used as it
# is. $PlatformNames lists the ones this repository uses.
# is. $PlatformNames lists the ones this repository uses. The few names only
# CI uses, which no customer sets, are in $CiNames.
#
# Only a name written out where a variable is read or set is checked. A
# pipeline setting, a builder parameter and a request's own environ are not
Expand Down Expand Up @@ -33,6 +34,10 @@ $script:PlatformNames = @(
'TEMP', 'TMP', 'TMPDIR')
$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')

$name = '(?<name>[A-Za-z0-9_]+)'
$quoted = "['`"]$name['`"]"

Expand Down Expand Up @@ -62,12 +67,15 @@ $script:ReadOrSetPatterns = @(
# "NAME: value".
$script:WorkflowKeyPattern = [regex]::new('^\s+(?<name>[A-Z_][A-Z0-9_]*):(?:\s|$)')

# Whether a name may be read or set: one this repository defines, or one the
# platform does.
# Whether a name may be read or set: one this repository defines, one only CI
# uses, or one the platform does.
function Test-EnvironmentName([string]$Name) {
if ($Name.StartsWith($script:Prefix, [StringComparison]::Ordinal)) {
return $true
}
if ($script:CiNames -ccontains $Name) {
return $true
}
if ($script:PlatformNames -contains $Name) {
return $true
}
Expand Down Expand Up @@ -144,9 +152,10 @@ Write-Output ("$read paths read, $($skipped.Count) skipped as not files: " +
if ($found.Count -gt 0) {
Write-Output $found
throw ("$($found.Count) environment variables are read or set under a " +
"name that does not start with $($script:Prefix) and is not one the " +
'platform defines.')
"name that does not start with $($script:Prefix) and is not one only " +
'CI uses or one the platform defines.')
}

Write-Output ('Every environment variable a tracked file reads or sets ' +
"starts with $($script:Prefix) or is one the platform defines.")
"starts with $($script:Prefix), is one only CI uses or is one the " +
'platform defines.')
Loading
Loading