Skip to content
51DegreesPublic

About

Shared scripts and documentation for continuous integration, testing, and deployment across 51Degrees repositories.

Topics

Resources

Contributing

Stars

1 star

Watchers

3 watching

Forks

Latest commit

 

History

1,706 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

This repository contains all the common scripts and documentation associated with continuous integration and deployment (CI/CD) used across the organisation.

The subfolders with language names contain an equivalent document detailing language specific detail that is common across all repositories using the language.

The reader should be familiar with PowerShell and common Git based CI/CD techniques.

Principles

The following rules are common across the organisation.

  • Minimal dependency between stages.
  • Relevant integration tests must be run against packages before they are released to the relevant package manager.
  • PowerShell scripts contain the implementation as they operate consistently across platform and avoid duplicating logic associated with a mixed environment.
  • PowerShell scripts contain all the necessary documentation at the top of the script.
  • PowerShell scripts have defined input parameters and outputs following PowerShell conventions.
  • Options defined in the repo are passed by the YAML script as parameters to the PowerShell script. Secrets are not parameters: each script reads the _51DEGREES_ secrets it needs from the environment, as described under Secrets and variables.
  • YAML scripts simply call the top level PowerShell scripts within the GitHub actions. Each YAML script will have a corresponding PowerShell script which can be used to test all the steps on any environment. These scripts must have the same name with only the file extension being different.
  • Orchestration of the PowerShell step scripts is handled by the top level PowerShell scripts as much as possible. There are some exceptions to this, e.g. running on multiple VM images needs to be handled in YAML.
  • GitHub triggers initiate the stages.
  • Use of GitHub actions and other platform specific features are minimised to enable portability of CI/CD. For example, cloning a repository is performed in PowerShell via a generic command line that works on Linux, Windows, and Mac rather than in a GitHub action. This ensures the PowerShell script can be tested outside a CI/CD deployment environment.
  • C/C++ is compiled using CMake on all platforms.
  • Versioning is handled by GitVersion.
  • Common PowerShell scripts are contained in this repository. Repository specific scripts are contained under the root ci folder.
  • Code that is in the main branch has passed all relevant tests. This is a critical gate to avoid repeating tests.
  • The package output from a repository in the organisation is used as the input to other packages in the same organisation via the relevant package manager. This ensures that the organisations published packages are treated just like any other dependency and are not given special treatment.
  • Branching strategy is covered in the relevant CONTRIBUTIONS.md for the repository and not covered here. All organisation repositories must have a main branch which can accept pull requests via automated tasks.

Runners Policy

All build workflows use standard GitHub hosted runners, including those that publish packages containing pre-built binary libraries.

Please note: on Linux distributions, the versions of glibc and libstdc++ (GLIBCXX) are tied to the underlying OS. These libraries are backward compatible binaries built against older versions will work on newer systems, but not vice versa. If your system has an older version than the one used during the build, you will need to compile the package from source. Instructions for doing so are provided in each repository.

Design

When implementing changes, see the Design Document for detailed descriptions of how each part works.

Contributing

For info on contributing to this, and other 51Degrees projects, see Contributing.

Workflows

Common Setup Steps

flowchart
subgraph com[Common Setup]
  style com fill:green;
  C1[Checkout Common]
  C2[Configure Git]
  C3[Clone Repo]
  C1-->C2-->C3
end
Loading

Nightly Publish Main

flowchart LR;

subgraph Nightly Publish Main
  conf -- Once per config where 'PackageRequirement'=true --> pbuild
  pbuild -- Combine pre-build files --> build
  build -- Once per config --> test
  test --> pub
end

subgraph conf[Configure]
  direction LR
  style conf fill:#00C5,stroke:#00C9,stroke-width:2px;
  A([Common Setup])
  style A fill:green;
  B[Get Next Package Version]
  C[Package Update Required]
  D[Get Build Options]
  A-->B-->C-->D

end

subgraph pbuild[Pre-Build]
  direction LR
  style pbuild fill:#00C5,stroke: #00C9,stroke-width:2px;
  style PB1 fill:green;
  PB1([Common Setup])
  PB2[Setup Environment]
  PB3[Build Package Requirements]
  PB4[Upload Package Artifact]
  PB1-->PB2-->PB3-->PB4
end

subgraph build[Build Package]
  direction LR
  style build fill:#00C5,stroke: #00C9,stroke-width:2px;
  style B1 fill:green;
  B1([Common Setup])
  B2[Setup Environment]
  B3[Download Package Artifacts]
  B4[Build Package]
  B5[Upload Package Artifact]
  B1-->B2-->B3-->B4-->B5
end

subgraph test[Test]
  direction LR
  style test fill:#00C5,stroke:#00C9,stroke-width:2px;
  style T1 fill:green;
  T1([Common Setup])
  T2[Fetch Assets]
  T3[Setup Environment]
  T4[Download Package Artifact]
  T5[Install Package From Artifact]
  T6[Run Integration Tests]
  T1-->T2-->T3-->T4-->T5-->T6
end

subgraph pub[Publish Package]
  direction LR
  style pub fill:#00C5,stroke:#00C9,stroke-width:2px;
  style P1 fill:green;
  P1([Common Setup])
  P2[Setup Environment]
  P3[Download Package Artifact]
  P4[Install Package From Artifact]
  P5[Publish Package]
  P6[Update Tag]
  P1-->P2-->P3-->P4-->P5-->P6
end

Loading

Nightly PR to Main

flowchart LR
  classDef green fill:green;

  subgraph "Nightly PR to Main"
    subgraph prs[Get Pull Requests]
      style prs fill:#00C5,stroke:#00C9,stroke-width:2px;
      X([Common Setup]):::green
      Y[Get Pull Requests]
      X-->Y
    end
    subgraph main[PR to Main]
      direction TB
      subgraph conf[Configure]
        direction LR
        style conf fill:#00C5,stroke:#00C9,stroke-width:2px;
        A([Common Setup]):::green
        B[Checkout Pull Request]
        C[Get Build Options]
        A-->B-->C
      end
      subgraph bat[Build and Test]
        direction LR
        F([Common Setup]):::green
        G[Checkout Pull Request]
        H[Fetch Assets]
        I[Setup Environment]
        J[Build Project]
        K[Run Unit Tests]
        L[Run Integration Tests]
        M[Run Performance Tests]
        F-->G-->H-->I-->J-->K-->L-->M
      end
      conf-- Once Per Config -->bat
    end
    prs-- Once Per PR -->main
  end
Loading

Nightly Submodule Update

  graph LR
  classDef green fill:green;
  subgraph "Nightly Submodule Update"
    direction LR
    A([Common Setup]):::green
    B[Update Sub Modules]
    C[Check for Changes]
    D[Commit Changes]
    E[Push Changes]
    F[Create Pull Request]
    A-->B-->C-->D-->E-->F
  end

Loading

Nightly Package Update

graph LR
classDef green fill:green;
  subgraph "Nightly Package Update"
    direction LR
    A([Common Setup]):::green
    B[Update Packages]
    C[Check for Changes]
    D[Commit Changes]
    E[Push Changes]
    F[Create Pull Request]
    A-->B-->C-->D-->E-->F
  end
Loading

Nightly Data File Update

graph LR
classDef green fill:green;
  subgraph "Nightly Data File Update"
    direction LR
    A([Common Setup]):::green
    B[Fetch Assets]
    C[Generate Accessors]
    D[Check For Changes]
    E[Commit Changes]
    F[Push Changes]
    G[PR to Main]
    A-->B-->C-->D-->E-->F-->G
  end
Loading

Nightly Documentation Update

graph LR
classDef green fill:green;
  subgraph "Nightly Documentation Update"
    direction LR
    A([Common Setup]):::green
    B[Clone Tools Repo]
    C[Clone Documentation Repo]
    D[Generate Documentation]
    E[Check For Changes]
    F[Commit Changes]
    G[Push Changes]
    A-->B-->C-->D-->E-->F-->G
  end
Loading

Monthly Copyright Update

graph LR
classDef green fill:green;
  subgraph "Monthly Copyright Update"
    direction LR
    A([Common Setup]):::green
    B[Clone Tools Repo]
    C[Update Copyright Messages]
    D[Check For Changes]
    E[Commit Changes]
    F[Create Pull Request]
    A-->B-->C-->D-->E-->F
  end
Loading

Triggers

Each of the triggers shown is described at a high level. More detail is provided in the associated scripts and the following summary.

Target branch

A repository with an rc branch takes every change to its default branch through rc. For such a repository the nightly works on rc:

  • The nightly's own pull requests, being the data file, package, submodule, example asset and copyright updates, target rc.
  • The Pull Requests job builds and merges pull requests into rc, and never merges into the default branch. Their performance is still compared with the default branch's history, as only its publish runs record one.

These updates therefore wait on rc, and reach the default branch and the published packages with the next release, when rc is merged into the default branch. A new property in a data file, for example, is published with the next release rather than the next night. A repository without rc works as before. steps/get-target-branch.ps1 makes the decision.

Nightly Data File Change

When data files used by the packages change new properties might be added or current ones deprecated. The strongly type accessors for the language might therefore need to change resulting in a new version of the resulting package. Every night, data files are fetched, and the auto generated strongly typed accessor code is updated. Any changes are then committed to a branch and a pull request to the target branch is created.

Nightly Package Dependency Update and Nightly Sub-Module Update

Every night any dependencies of the package are updated automatically to the latest patch version of that package or the latest commit of the sub-module's specified branch. This includes any dependencies on packages within the organisation. Where changes are identified a branch is created and a PR to the target branch is initiated. The tests associated with any PR to the target branch will identify any failures for engineers to address before the updated versions can be used.

Pull Requests

All tests associated with the repository are run only at this point to avoid repetition. Code can only be present in the main branch of the repository if all tests have passed.

Pull Requests can only be initiated by a project Contributor, Administrator, or GitHub actions.

A repository can build each pull request on only the entries of ci/options.json its changes need, by adding ci/select-options.ps1, as Select Options describes. Without that script every entry is built. release-pull-request.yml builds the release pull request from rc into the default branch on every entry, as a dry run that merges nothing, so everything a release carries is built and tested in full before it reaches the default branch.

These inputs of nightly-pull-requests.yml keep the behaviour described above unless a repository changes them.

Input Default Effect
fail-fast true When one configuration of a pull request fails, the others are cancelled. With false they finish, so "Re-run failed jobs" repeats only the one that failed.
full-matrix false Builds every entry, even where ci/select-options.ps1 would choose fewer.
build-without-pull-requests true When no pull request is eligible, builds the branch itself on every entry. A run started by hand can set it to false and leave that build to the nightly.

Nightly Package

This job should only be run once all the other nightly jobs have completed.

Any changes to the target branch are published automatically on a nightly basis as a new package at the target package manager environment.

This can also be run manually against any branch. The automatic versioning logic will increase the last version component of the closest reachable commit on selected branch. Some examples:

  • The closest tagged commit on the main branch is tagged as 4.4.9. The next version will be 4.4.10.
  • The closest tagged commit on the version/4.5 branch is tagged as 4.5.0-alpha.0. The next version will be 4.5.0-alpha.1.

When a branch is split off of main (or any other branch that gets published) and has to run this workflow, its versioning will have to change to avoild conflicting tags with the parent branch. This change has to be done manually once, as CI cannot know the new desired version (4.5.0, 5.0.0, 4.5.0-alpha.0, etc.) otherwise. The automatic tags will then follow the manually specified version.

Nightly Documentation Update

Any changes to the main branch are used to generate the latest documentation. This is then published to the gh-pages branch of the reposiory.

Nightly Pipeline

This is a wrapper workflow that's not present in common-ci. It calls other nightly workflows (some in paralell, others sequentially) as part of a single workflow to preserve the trigger metadata between them, and allow running the entire Nightly workflows suite from any branch. This approach is required, because unlike PowerShell scripts, that can be parametrized to run from any branch, some of the actions that the workflows call (e.g. publish-unit-test-result-action) use the branch from GitHub's metadata.

The wrapper should usually just be a combination of other nightly workflows, with dependencies between stages specified using the needs job property instead of workflow_run triggers used previously.

One limitation of such approach is that GitHub's scheduled pipelines always run from main, but we need to be able to schedule them on any branch. To work around this limitation a separate scheduler workflow (nightly-pipeline-prerelease.yml) is used. Its only task is to trigger the Nightly Pipeline workflow from the specified branch, using the GitHub API.

The unified nightly pipeline is opt-in. Only repositories that need to run the nightly suite from branches other than main have to use it. Other repositories can continue using the previous system, based on workflow_run triggers.

Monthly Copyright Update

If the copyright is updated, the source code files are all updated with the latest copyright in the header of the file.

This does no happen often, so the workflow can be run monthly rather than nightly.

Common Scenarios

New property in data file

The Data File Change trigger creates new auto generated code for the strongly typed accessors. These are pushed to a branch and a PR to the target branch commenced. All the tests associated with the repository will then be run. If they fail, then the engineers will be alerted to a problem. If they pass, then the PR will be approved and the target branch updated. When the next nightly publish of packages occurs then the new property will be included in the package, or, where the target branch is rc, the first publish after the next release.

Update dependency

A package that the organisation uses is updated to a new version within the same major.minor version. The nightly dependency check will pick up on the new version and create a branch and associated PR to the target branch. The changes will then propagate to the published packages if the tests executed for any PR pass.

Organisation package update

Packages associated with the organisation are treated like any other package dependency. Once the package manager has the new version the dependent packages will be updated automatically.

Common Steps

For details of the common scripts, see Common Steps.

Prerequisites

To run these PowerShell scripts, either locally, or in a CI/CD pipeline, the following prerequisites must be set up.

  • Git CLI
  • Hub CLI
  • CI_ACCESS_TOKEN environment variable, a GitHub token that the scripts sign in with (the workflows set it from the organization secret of that name)
  • Some repositories require a cloud resource key. This can be obtained on the configuration page

Secrets and variables

The _51DEGREES_ prefix is only for the names a customer uses, in the demos and the examples, such as _51DEGREES_RESOURCE_KEY_FREE and _51DEGREES_CLOUD_ENDPOINT. A secret that only CI uses has no prefix, and its name says what it does. CI_ACCESS_TOKEN is the token the jobs sign in to GitHub with, and PUBLISH_ACCESS_TOKEN is the token the publishing steps use.

Every secret the workflows read is an organization secret. A calling workflow passes secrets: inherit, and the reusable workflows declare no secret of their own.

In each job that builds, tests or publishes, one step, steps/export-secrets.ps1, exports the secrets and variables into the environment, each under its own name, so the scripts and tests that follow read each by that name. Every secret and every variable whose name starts with _51DEGREES_ is exported, so a new organization secret or variable with a _51DEGREES_ name reaches the jobs with no change here. The secrets that only CI uses are listed in steps/ci-secrets.psd1, and no other name is exported. The export renames nothing and fills no name from another. A name holds one thing, so a name the step exports that is both a secret and a variable fails the step. The whole secrets context is read in that step alone, apart from the asset prefetch, where it is also hashed into the cache key. The prefetch exports the secrets in a step of its own as well, and runs the repository's ci/fetch-assets.ps1 in the next step, which has the exported names and not the secrets context. A step in a job without the export step reads CI_ACCESS_TOKEN or PUBLISH_ACCESS_TOKEN alone, by name, apart from the asset prefetch, which also takes the data file license described below.

An organization or repository variable, such as _51DEGREES_CLOUD_ENDPOINT, reaches the called workflows with no change to the calling workflow.

A job receives only the secrets it uses. steps/ci-secrets.psd1 lists the secrets that only CI uses by the jobs that take them. The export step gives CI_ACCESS_TOKEN to every job, the secrets used to publish, such as PUBLISH_ACCESS_TOKEN and NUGET_API_KEY, only to the job that publishes, which passes -Publish, and the secrets used to sign, such as CODE_SIGNING_KEY_VAULT_URL, only to the job that signs, which passes -Sign. The license the data files are downloaded with, LICENSE_KEY_V4TAC_IPIV4ENTERPRISE, is listed under Data, which the export never takes. The asset prefetch step, the Build and Test step and the Test step set _51DEGREES_LICENSE_KEY from it, for the data file downloads and the data file update example tests those steps run, and no other step or job has _51DEGREES_LICENSE_KEY in its environment. Outside the export step, the check of the weekly release interval in the Configure job reads PUBLISH_ACCESS_TOKEN by name. A new secret that only CI uses is added to that list. The script that publishes or signs reads each at the point of use. No script in this repository takes a token as a parameter.

A secret that only one repository's own build and test scripts read is listed by that repository, not here. It goes in the repository's ci/ci-secrets.psd1, under Scripts:

@{
    Scripts = @(
        'NAME_OF_THE_SECRET'
    )
}

The jobs that run the repository's build and test scripts, BuildAndTest in nightly-pull-request.yml and PreBuild and Test in nightly-publish.yml and nightly-publish-main.yml, read that file with steps/get-caller-ci-secrets.ps1 and pass it to the export step as -CallerList. BuildAndTest reads it from the branch the pull request goes into, except in release-pull-request.yml, where it reads it from rc, the branch whose scripts the release builds. PreBuild and Test read it from the branch they build. No job that publishes or signs takes it. A repository with no such file gets nothing more. The asset prefetch does not take the list. A listed name is a secret, in capitals, digits and underscores, that does not start _51DEGREES_ and that steps/ci-secrets.psd1 does not list in any class. Any other listed name stops the job, naming it, and so does a listed name the job does not have as a secret. A repository can list any other secret it has access to, so access to each organization secret is set per repository.

A name that a tool defines, such as GITHUB_TOKEN or twine's TWINE_PASSWORD, is set at the point of use straight from the secret.

The export step writes only names to the log, for variables as for secrets.

Environment variable names

The names every language reads are a shared contract that lives in the specifications repository. Each language repository documents the names only it reads.

Package distribution

PACKAGE_DISTRIBUTION.md says the kinds of place a 51Degrees package is listed publicly, being the package registries, SourceForge, Context7 and lists kept by other projects, and what each package release must update. Every package release updates every place the package is listed.

Reusable actions

There is also a set of actions that can be used independently from the framework described above, see their README.

About

Shared scripts and documentation for continuous integration, testing, and deployment across 51Degrees repositories.

Topics

Resources

Contributing

Stars

1 star

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages