Skip to content
Open
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
161 changes: 161 additions & 0 deletions .github/workflows/examples-published.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
name: Examples vs Published Packages

# Runs the examples' own tests against the packages on Maven Central. Only
# the two examples trees and their tests come from this checkout. The
# packages the examples name by version are pinned to the version given when
# the workflow is run by hand, after a publish to the version the publish
# released each at, and otherwise to the latest release on Maven Central.
# ci/run-published-examples.ps1 chooses the versions and runs the tests.
#
# It runs by hand on a branch (gh workflow run "Examples vs Published
# Packages" --ref <branch>), after each run of the two workflows that
# publish, and on a pull request that changes this file or the script. An
# example that needs a change not yet released fails here until the release,
# which is why it does not run on other pull requests.
#
# The tests run on the free data files, with the TAC and Enterprise IP
# Intelligence data files the data file update examples' tests need, and the
# keys the cloud tests need. A missing key or data file fails the run, and so
# do a tree that ran no tests and a test that skipped, except the few the
# script lists as skipping here by design. A pull request from a fork gets no
# secrets, so the job does not run for one.

on:
workflow_dispatch:
inputs:
version:
description: 'Version of every published package, such as 4.6.2, or empty for the latest of each on Maven Central'
type: string
default: ''
# A run of either may publish packages, and one that failed may still have
# published some, so only a cancelled run is passed over.
workflow_run:
workflows: [Publish, Nightly Pipeline]
types: [completed]
pull_request:
paths:
- '.github/workflows/examples-published.yml'
- 'ci/run-published-examples.ps1'
- 'ci/run-published-examples.Tests.ps1'
- 'ci/packages.ps1'

permissions:
contents: read

# Every compiler and tool warning is an error in the builds 51Degrees runs.
# The poms read this variable.
env:
_51DEGREES_WARNINGS_AS_ERRORS: 'true'

defaults:
run:
shell: pwsh

jobs:
published:
name: examples vs published packages
if: >-
(github.event_name != 'workflow_run' ||
github.event.workflow_run.conclusion != 'cancelled') &&
github.event.pull_request.head.repo.fork != true
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
# A missing key would leave the cloud tests skipped, so it fails the
# run here, naming it.
- name: Check the keys are available
env:
_51DEGREES_RESOURCE_KEY_BESPOKE: ${{ secrets._51DEGREES_RESOURCE_KEY_BESPOKE }}
_51DEGREES_RESOURCE_KEY_BASIC: ${{ secrets._51DEGREES_RESOURCE_KEY_BASIC }}
run: |
$missing = @('_51DEGREES_RESOURCE_KEY_BESPOKE', '_51DEGREES_RESOURCE_KEY_BASIC' |
Where-Object { -not [Environment]::GetEnvironmentVariable($_) })
if ($missing) {
throw ("The organization secret $($missing -join ', ') is " +
'empty or missing, so the cloud examples cannot be tested.')
}

# After a publish, the commit that was published. The data repository
# inside cxx holds a link for each data file, where the examples look.
# The tags a publish pushes are read from origin, so none are fetched.
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha }}
persist-credentials: false
submodules: recursive

- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17'

# 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
uses: 51Degrees/common-ci/actions/fetch-assets@main
with:
assets: |
51Degrees-LiteV4.1.hash
20000 Evidence Records.yml
51Degrees-IPIV4AsnIpiV41.ipi
51Degrees-LiteIpiV41.ipi

# The data file update examples' tests serve a copy of the TAC data
# file and of the Enterprise IP Intelligence data file. They come from
# the same shared copy, decrypted with CACHE_ENCRYPTION_KEY, which
# common-ci's step reads from this step's environment. Nothing here
# keeps them.
- name: Restore the licensed data files
uses: 51Degrees/common-ci/actions/fetch-assets@main
env:
CACHE_ENCRYPTION_KEY: ${{ secrets.CACHE_ENCRYPTION_KEY }}
with:
assets: |
TAC-HashV41.hash
51Degrees-EnterpriseIpiV41.ipi

# Under the names the data repository saves them as, where the
# examples look. A missing file fails the job here, because the tests
# would skip or fail without it.
- name: Put the data files where the examples look for them
run: |
$dd = 'cxx/data/device-detection'
$ipi = 'cxx/data/ip-intelligence'
$files = [ordered]@{
'51Degrees-LiteV4.1.hash' = "$dd/51Degrees-LiteV4.1.hash"
'20000 Evidence Records.yml' = "$dd/20000 Evidence Records.yml"
'TAC-HashV41.hash' = "$dd/TAC-HashV41.hash"
'51Degrees-IPIV4AsnIpiV41.ipi' = "$ipi/51Degrees-IPIV4AsnIpiV41.ipi"
'51Degrees-LiteIpiV41.ipi' = "$ipi/51Degrees-LiteV41.ipi"
'51Degrees-EnterpriseIpiV41.ipi' = "$ipi/51Degrees-EnterpriseIpiV41.ipi"
}
foreach ($asset in $files.Keys) {
$source = Join-Path assets $asset
if (-not (Test-Path -LiteralPath $source -PathType Leaf)) {
Write-Host "::error title=Missing data file::$asset was not fetched."
exit 1
}
Move-Item -LiteralPath $source -Destination $files[$asset]
}

# The cloud tests read _51DEGREES_RESOURCE_KEY_BESPOKE, and the Human
# Confidence test also _51DEGREES_RESOURCE_KEY_BASIC. After a publish,
# each package it tagged is pinned to the version its tag names.
- name: Test the examples against the published packages
env:
_51DEGREES_RESOURCE_KEY_BESPOKE: ${{ secrets._51DEGREES_RESOURCE_KEY_BESPOKE }}
_51DEGREES_RESOURCE_KEY_BASIC: ${{ secrets._51DEGREES_RESOURCE_KEY_BASIC }}
# The cloud service the tests ask. The name is removed when the
# variable is not set, so the tests ask the public one.
_51DEGREES_CLOUD_ENDPOINT: ${{ vars._51DEGREES_CLOUD_ENDPOINT }}
# The version typed when the workflow is run by hand, which is read
# from here rather than written into the script.
_51DEGREES_PACKAGE_VERSION: ${{ inputs.version }}
run: |
if (-not $env:_51DEGREES_CLOUD_ENDPOINT) {
Remove-Item Env:_51DEGREES_CLOUD_ENDPOINT -ErrorAction SilentlyContinue
}
./ci/run-published-examples.ps1 -Version "$env:_51DEGREES_PACKAGE_VERSION".Trim() `
-PublishedCommit '${{ github.event.workflow_run.head_sha }}'
17 changes: 17 additions & 0 deletions ci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ repositories used to do for one package tree each.

[run-fresh-clone-example.Tests.ps1](run-fresh-clone-example.Tests.ps1)
tests it with `pwsh -File` and with the workflow's own calls.
- [run-published-examples.ps1](run-published-examples.ps1) runs the tests of
both examples trees against the packages on Maven Central for
[examples-published.yml](../.github/workflows/examples-published.yml). It
pins the packages the examples name by version to the version given, to the
version a publish tagged once Maven Central lists it, or to the latest
release, and starts Maven from an empty local repository. It fails unless
each tree ran tests, every test passed or is one of the few it lists as
skipping by design, and every pinned package came from Maven Central. To
run it by hand, put the data files in `cxx/data` and set the keys, then from
the repository root give

```
pwsh -File ./ci/run-published-examples.ps1 -Version 4.6.2
```

[run-published-examples.Tests.ps1](run-published-examples.Tests.ps1) tests
it with a stand-in for Maven and a folder in place of Maven Central.
- [run-performance-tests.ps1](run-performance-tests.ps1) measures the Pipeline
API, Device Detection and IP Intelligence and writes one results file per
configuration. The Device Detection and IP Intelligence metrics are prefixed
Expand Down
7 changes: 5 additions & 2 deletions ci/check-environment-variable-names.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ $script:PlatformNames = @(
# check.
'polyglot.engine.WarnInterpreterOnly'
# GitHub Actions and its runners.
'CI', 'GITHUB_ACTIONS', 'GITHUB_ENV', 'GITHUB_TOKEN', 'CHROME_BIN',
'CHROMEWEBDRIVER'
'CI', 'GITHUB_ACTIONS', 'GITHUB_ENV', 'GITHUB_STEP_SUMMARY', 'GITHUB_TOKEN',
'CHROME_BIN', 'CHROMEWEBDRIVER'
)

# The names only CI uses. No customer sets them, so they have no
Expand All @@ -71,6 +71,9 @@ $script:CiNames = @(
# False on the entries that leave the live cloud tests to another entry
# of the same operating system. setup-environment.ps1 sets it.
'LIVE_CLOUD_TESTS'
# The key that decrypts the licensed data files in common-ci's shared
# copy, which its fetch-assets step reads.
'CACHE_ENCRYPTION_KEY'
)

# The system properties the JDK defines start with one of these.
Expand Down
10 changes: 10 additions & 0 deletions ci/packages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ $env:_51DEGREES_WARNINGS_AS_ERRORS = 'true'
# Arguments every Maven call in these scripts passes.
$MavenOptions = '--batch-mode', '--no-transfer-progress'

# The examples' properties that name the version of a package they use, which
# the publish sets to the version it built and the Examples vs Published
# Packages workflow to the versions on Maven Central.
$ExampleVersionProperties = @{
'device-detection.version' = 'device-detection'
'ip-intelligence.version' = 'ip-intelligence'
'pipeline.cloudrequestengine.version' = 'pipeline.cloudrequestengine'
'pipeline.jsonbuilder.version' = 'pipeline.jsonbuilder'
}

# Every Maven call that compiles runs on this JDK, which compiles for Java 8
# through each tree's java-8-api profile. The tests still run on each entry's
# own JDK. javac 21 warns that release 8 is obsolete, which -Werror makes an
Expand Down
9 changes: 0 additions & 9 deletions ci/release.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ if ($null -eq $releasePlan) {
. $releasePlan
Remove-Variable releasePlan

# The examples' properties that name the version of a package they use, which
# the publish sets to the version it built.
$ExampleVersionProperties = @{
'device-detection.version' = 'device-detection'
'ip-intelligence.version' = 'ip-intelligence'
'pipeline.cloudrequestengine.version' = 'pipeline.cloudrequestengine'
'pipeline.jsonbuilder.version' = 'pipeline.jsonbuilder'
}

# The packages a publish builds. When nothing is to be released, every package
# is built at its released version, so that the tests have packages to install
# and the nightly publish passes without publishing anything.
Expand Down
Loading
Loading