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
1 change: 1 addition & 0 deletions .github/jsonnet/GIT_VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1e5064bfee9299e657d1d478626dfb60036ea580
16 changes: 16 additions & 0 deletions .github/jsonnet/actions.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* GitHub Action plugin references
*
* Centralised SHA-pinned references for external GitHub Actions used across workflows.
* Pinning to a SHA (rather than a tag) protects against supply-chain attacks where a
* tag is moved to point at a malicious commit. The trailing comment records the
* human-readable version that the SHA corresponds to at the time of pinning.
*/
{
checkout_action: 'actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd', // v6
gcp_auth_action: 'google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093', // v3
gcp_setup_gcloud_action: 'google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db', // v3
pulumi_action: 'pulumi/actions@cd99a7f8865434dd3532b586a26f9ebea596894f', // v5
onepassword_load_secrets_action: '1password/load-secrets-action@92467eb28f72e8255933372f1e0707c567ce2259', // v4
slack_action: 'act10ns/slack@d96404edccc6d6467fc7f8134a420c851b1e9054', // v2
}
7 changes: 5 additions & 2 deletions .github/jsonnet/base.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ local misc = import 'misc.jsonnet';
* @param {object} [concurrency=null] - Job-level concurrency settings
* @param {boolean} [continueOnError=null] - Whether to continue workflow if job fails
* @param {object} [env=null] - Environment variables for all steps in the job
* @param {object} [strategy=null] - GitHub Actions matrix strategy (e.g., {matrix: {shard: [1,2,3]}, 'fail-fast': false})
* @returns {jobs} - GitHub Actions job definition
*/
ghJob(
Expand All @@ -58,6 +59,7 @@ local misc = import 'misc.jsonnet';
concurrency=null,
continueOnError=null,
env=null,
strategy=null,
)::
{
[name]: {
Expand All @@ -82,7 +84,8 @@ local misc = import 'misc.jsonnet';
(if permissions == null then {} else { permissions: permissions }) +
(if concurrency == null then {} else { concurrency: concurrency }) +
(if continueOnError == null then {} else { 'continue-on-error': continueOnError }) +
(if env == null then {} else { env: env }),
(if env == null then {} else { env: env }) +
(if strategy == null then {} else { strategy: strategy }),
},

/**
Expand Down Expand Up @@ -159,7 +162,7 @@ local misc = import 'misc.jsonnet';
* @docs https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#jobsjob_idsteps
*
* @param {string} name - Display name for the step in the GitHub UI
* @param {string} uses - The action to use (e.g., 'actions/checkout@v4', './path/to/action')
* @param {string} uses - The action to use (e.g., 'actions/checkout@v6', './path/to/action')
* @param {object} [env=null] - Environment variables for this step
* @param {object} [with=null] - Input parameters to pass to the action
* @param {string} [id=null] - Unique identifier for this step (used to reference outputs)
Expand Down
2 changes: 1 addition & 1 deletion .github/jsonnet/clusters.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local misc = import 'misc.jsonnet';

/**
* Kubernetes Cluster Configuration
*
*
* This module defines configuration for different Kubernetes clusters used for deployments.
* Each cluster configuration includes project information, authentication secrets, and
* node selector settings for job scheduling.
Expand Down
4 changes: 2 additions & 2 deletions .github/jsonnet/deployment.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ local notifications = import 'notifications.jsonnet';
function(deploymentTarget)
base.action(
'publish-deploy-' + deploymentTarget + '-event',
'chrnorm/deployment-action@v2',
'chrnorm/deployment-action@500aa6a23c81ffa1acf71072aee3cfa2cc2e556a', // v2
ifClause=ifClause,
with={
token: misc.secret('VIRKO_GITHUB_TOKEN'),
Expand Down Expand Up @@ -173,7 +173,7 @@ local notifications = import 'notifications.jsonnet';
updateDeploymentStatus(status='${{ job.status }}')::
base.action(
'Update deployment status',
'chrnorm/deployment-status@v2',
'chrnorm/deployment-status@6df8d036fd2fee9eb82936733953da1f8382b41e', // v2
with={
state: status,
['deployment-id']: '${{ github.event.deployment.id }}',
Expand Down
18 changes: 18 additions & 0 deletions .github/jsonnet/helm.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ local services = import 'services.jsonnet';
* @param {boolean} [fetchDependencies=false] - Whether to fetch Helm dependencies
* @param {boolean} [wait=false] - Whether to wait for resources to be ready before marking the release as successful
* @param {string} [timeout=null] - Time to wait for resources (pods) to become ready (e.g., '5m')
* @param {string} [runsOn=null] - GitHub Actions runner to use for the job
* @returns {jobs} - Complete GitHub Actions job for production deployment
*/
helmDeployProdJob(
Expand All @@ -145,9 +146,11 @@ local services = import 'services.jsonnet';
fetchDependencies=false,
wait=false,
timeout=null,
runsOn=null,
)::
base.ghJob(
'deploy-prod',
runsOn=runsOn,
ifClause="${{ github.event.deployment.environment == '" + environment + "' }}",
image=image,
useCredentials=useCredentials,
Expand Down Expand Up @@ -213,6 +216,7 @@ local services = import 'services.jsonnet';
* @param {boolean} [fetchDependencies=false] - Whether to fetch Helm dependencies
* @param {boolean} [wait=false] - Whether to wait for resources to be ready before marking the release as successful
* @param {string} [timeout=null] - Time to wait for resources (pods) to become ready (e.g., '5m')
* @param {string} [runsOn=null] - GitHub Actions runner to use for the job
* @returns {jobs} - Complete GitHub Actions job for test deployment
*/
helmDeployTestJob(
Expand All @@ -225,9 +229,11 @@ local services = import 'services.jsonnet';
fetchDependencies=false,
wait=false,
timeout=null,
runsOn=null,
)::
base.ghJob(
'deploy-test',
runsOn=runsOn,
ifClause="${{ github.event.deployment.environment == 'test' }}",
image=image,
useCredentials=useCredentials,
Expand Down Expand Up @@ -296,6 +302,7 @@ local services = import 'services.jsonnet';
* @param {boolean} [fetchDependencies=false] - Whether to fetch Helm dependencies
* @param {boolean} [wait=false] - Whether to wait for resources to be ready before marking the release as successful
* @param {string} [timeout=null] - Time to wait for resources (pods) to become ready (e.g., '5m')
* @param {string} [runsOn=null] - GitHub Actions runner to use for the job
* @returns {jobs} - Complete GitHub Actions job for PR deployment
*/
helmDeployPRJob(
Expand All @@ -308,9 +315,11 @@ local services = import 'services.jsonnet';
fetchDependencies=false,
wait=false,
timeout=null,
runsOn=null,
)::
base.ghJob(
'deploy-pr',
runsOn=runsOn,
image=image,
useCredentials=useCredentials,
steps=[
Expand Down Expand Up @@ -369,6 +378,7 @@ local services = import 'services.jsonnet';
* @param {boolean} [fetchDependencies=fetchDependencies] - Whether to fetch Helm dependencies
* @param {boolean} [wait=false] - Whether to wait for resources to be ready before marking the release as successful
* @param {string} [timeout=null] - Time to wait for resources (pods) to become ready (e.g., '5m')
* @param {string} [runsOn=null] - GitHub Actions runner to use for the job
* @returns {jobs} - Complete GitHub Actions job for PR cleanup
*/
helmDeletePRJob(
Expand All @@ -380,9 +390,11 @@ local services = import 'services.jsonnet';
fetchDependencies=fetchDependencies,
wait=false,
timeout=null,
runsOn=null,
)::
base.ghJob(
'helm-delete-pr',
runsOn=runsOn,
image=images.default_job_image,
useCredentials=false,
steps=[
Expand Down Expand Up @@ -483,6 +495,7 @@ local services = import 'services.jsonnet';
* @param {boolean} [fetchDependencies=false] - Whether to fetch Helm dependencies
* @param {boolean} [wait=false] - Whether to wait for resources to be ready before marking the release as successful
* @param {string} [timeout=null] - Time to wait for resources (pods) to become ready (e.g., '5m')
* @param {string} [runsOn=null] - GitHub Actions runner to use for the job
* @returns {jobs} - Complete GitHub Actions job for canary deployment
*/
helmDeployCanaryJob(
Expand All @@ -495,9 +508,11 @@ local services = import 'services.jsonnet';
fetchDependencies=false,
wait=false,
timeout=null,
runsOn=null,
)::
base.ghJob(
'deploy-canary',
runsOn=runsOn,
image=image,
useCredentials=useCredentials,
ifClause="${{ github.event.deployment.environment == 'canary' }}",
Expand Down Expand Up @@ -566,6 +581,7 @@ local services = import 'services.jsonnet';
* @param {boolean} [fetchDependencies=false] - Whether to fetch Helm dependencies
* @param {boolean} [wait=false] - Whether to wait for resources to be ready before marking the release as successful
* @param {string} [timeout=null] - Time to wait for resources (pods) to become ready (e.g., '5m')
* @param {string} [runsOn=null] - GitHub Actions runner to use for the job
* @returns {jobs} - Complete GitHub Actions job to kill canary deployment
*/
helmKillCanaryJob(
Expand All @@ -576,9 +592,11 @@ local services = import 'services.jsonnet';
fetchDependencies=false,
wait=false,
timeout=null,
runsOn=null,
)::
base.ghJob(
'kill-canary',
runsOn=runsOn,
ifClause="${{ github.event.deployment.environment == 'kill-canary' || github.event.deployment.environment == 'production' }}",
image=images.default_job_image,
useCredentials=false,
Expand Down
2 changes: 1 addition & 1 deletion .github/jsonnet/images.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Images are primarily hosted on Google Cloud registries (GCR and Artifact Registry).
*/
{
jsonnet_bin_image: 'europe-docker.pkg.dev/unicorn-985/private-images/docker-images_jsonnet:v1',
jsonnet_bin_image: 'europe-docker.pkg.dev/unicorn-985/private-images/docker-images_jsonnet:v2',
helm_action_image: 'docker://europe-docker.pkg.dev/unicorn-985/public-images/helm-action:v4',
mysql_action_image: 'docker://europe-docker.pkg.dev/unicorn-985/public-images/docker-images_mysql-cloner-action:v2',
docker_action_image: 'docker://europe-docker.pkg.dev/unicorn-985/public-images/push-to-gcr-github-action:v1',
Expand Down
1 change: 1 addition & 0 deletions .github/jsonnet/index.jsonnet
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(import 'base.jsonnet') +
{ actions: import 'actions.jsonnet' } +
{ clusters: import 'clusters.jsonnet' } +
(import 'databases.jsonnet') +
(import 'docker.jsonnet') +
Expand Down
31 changes: 20 additions & 11 deletions .github/jsonnet/misc.jsonnet
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local actions = import 'actions.jsonnet';
local base = import 'base.jsonnet';
local images = import 'images.jsonnet';

Expand Down Expand Up @@ -72,13 +73,13 @@ local images = import 'images.jsonnet';
sshSteps +
base.action(
'Check out repository code via ssh',
'actions/checkout@v4',
actions.checkout_action,
with=with + (if preferSshClone then { 'ssh-key': '${{ secrets.VIRKO_GITHUB_SSH_KEY }}' } else {}),
ifClause='${{ ' + (if ifClause == null then '' else '( ' + localIfClause + ' ) && ') + " ( steps.check-binaries.outputs.sshBinaryExists == 'true' && steps.check-binaries.outputs.gitBinaryExists == 'true' ) }}",
) +
base.action(
'Check out repository code via https',
'actions/checkout@v4',
actions.checkout_action,
with=with,
ifClause='${{ ' + (if ifClause == null then '' else '( ' + localIfClause + ' ) && ') + " ( steps.check-binaries.outputs.sshBinaryExists == 'false' || steps.check-binaries.outputs.gitBinaryExists == 'false' ) }}",
) +
Expand All @@ -102,7 +103,7 @@ local images = import 'images.jsonnet';
(if includeSubmodules then { submodules: 'recursive' } else {});
base.action(
'Check out repository code',
'actions/checkout@v4',
actions.checkout_action,
with=with,
ifClause=ifClause
) +
Expand Down Expand Up @@ -187,8 +188,9 @@ local images = import 'images.jsonnet';
echo "Possible reasons:";
echo " - You updated jsonnet files, but did not regenerate the workflows.";
echo " To regenerate jsonnet run: 'rm .github/workflows/*; jsonnet -m .github/workflows/ -S .github.jsonnet'";
echo " - You used the wrong jsonnet binary. In this case, the newlines at the end of the files differ.";
echo " To fix, install the go binary. On mac, run 'brew uninstall jsonnet && brew install go-jsonnet'";
echo " - You used the wrong jsonnet binary (version). In this case, the newlines at the end of the files differ.";
echo " - You must use go-jsonnet version 0.22 or higher. Earlier versions do not generate the yml with trailing newline."
echo " To fix, install the go binary (^0.22). On mac, run 'brew uninstall jsonnet && brew install go-jsonnet'";
exit 1;
|||
),
Expand All @@ -205,6 +207,7 @@ local images = import 'images.jsonnet';
* @param {string} [bodyUpdateAction='suffix'] - How to update the body ('suffix', 'prefix', 'replace')
* @param {string} [titleUpdateAction='prefix'] - How to update the title ('suffix', 'prefix', 'replace')
* @param {object} [otherOptions={}] - Additional options to pass to the action
* @param {string} [runsOn=null] - GitHub Actions runner to use for the job
* @returns {workflows} - GitHub Actions pipeline for automatic PR description updates
*/
updatePRDescriptionPipeline(
Expand All @@ -215,6 +218,7 @@ local images = import 'images.jsonnet';
bodyUpdateAction='suffix',
titleUpdateAction='prefix',
otherOptions={},
runsOn=null,
)::
base.pipeline(
'update-pr-description',
Expand All @@ -224,6 +228,7 @@ local images = import 'images.jsonnet';
jobs=[
base.ghJob(
'update-pr-description',
runsOn=runsOn,
steps=[
base.action(
'update-pr-description',
Expand Down Expand Up @@ -417,7 +422,7 @@ local images = import 'images.jsonnet';
image=null,
runsOn='ubuntu-latest',
steps=[
base.action('checkout', 'actions/checkout@v4'),
base.action('checkout', actions.checkout_action),
base.action(
'Run delete-old-branches-action',
'beatlabs/delete-old-branches-action@4eeeb8740ff8b3cb310296ddd6b43c3387734588',
Expand Down Expand Up @@ -472,7 +477,7 @@ local images = import 'images.jsonnet';
base.step('git safe directory', 'git config --global --add safe.directory $PWD'),
base.action(
'check-for-changes',
uses='dorny/paths-filter@v2',
uses='dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d', // v4
id='changes',
with={
filters: |||
Expand All @@ -492,9 +497,10 @@ local images = import 'images.jsonnet';
*
* @param {string} name - The name of the GitHub job
* @param {array} jobs - Array of job objects to wait for
* @param {string} [runsOn=null] - GitHub Actions runner to use for the job
* @returns {jobs} - GitHub Actions job that waits for the given jobs to finish
*/
awaitJob(name, jobs)::
awaitJob(name, jobs, runsOn=null)::
local dependingJobs = std.flatMap(
function(job)
local jobNameArray = std.objectFields(job);
Expand All @@ -504,6 +510,7 @@ local images = import 'images.jsonnet';
[
base.ghJob(
'await-' + name,
runsOn=runsOn,
ifClause='${{ always() }}',
needs=dependingJobs,
useCredentials=false,
Expand Down Expand Up @@ -567,18 +574,20 @@ local images = import 'images.jsonnet';
* Useful for automatically approving renovate PRs or other trusted automation.
*
* @param {array} [users=['gynzy-virko']] - Array of usernames to auto-approve PRs for
* @param {string} [runsOn=null] - GitHub Actions runner to use for the job
* @returns {workflows} - GitHub Actions pipeline that auto-approves PRs from specified users
*/
autoApprovePRs(users=['gynzy-virko'])::
autoApprovePRs(users=['gynzy-virko'], runsOn=null)::
base.pipeline(
'auto-approve-prs',
[
base.ghJob(
'auto-approve',
runsOn=runsOn,
steps=[
base.action(
'auto-approve-prs',
'hmarr/auto-approve-action@v4',
'hmarr/auto-approve-action@8f929096a962e83ccdfa8afcf855f39f12d4dac7', // v4
),
],
useCredentials=false,
Expand Down Expand Up @@ -699,7 +708,7 @@ local images = import 'images.jsonnet';
steps=[
base.action(
'Close stale PRs',
'actions/stale@v10',
'actions/stale@b5d41d4e1d5dceea10e7104786b73624c18a190f', // v10
with={
'days-before-stale': daysBeforeStale,
'days-before-close': daysBeforeClose,
Expand Down
3 changes: 3 additions & 0 deletions .github/jsonnet/newrelic.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ local pnpm = import 'pnpm.jsonnet';
* @param {string} [image='mirror.gcr.io/node:20.17'] - Docker image to use for the job
* @param {boolean} [useCredentials=false] - Whether to use Docker registry credentials
* @param {string} [packageManager='yarn'] - Package manager to use ('yarn' or 'pnpm')
* @param {string} [runsOn=null] - GitHub Actions runner to use for the job
* @returns {jobs} - GitHub Actions job definition for New Relic deployment notification
*/
postReleaseToNewRelicJob(
Expand All @@ -23,9 +24,11 @@ local pnpm = import 'pnpm.jsonnet';
image='mirror.gcr.io/node:20.17',
useCredentials=false,
packageManager='yarn',
runsOn=null,
)::
base.ghJob(
'post-newrelic-release',
runsOn=runsOn,
image=image,
useCredentials=useCredentials,
ifClause="${{ github.event.deployment.environment == 'production' }}",
Expand Down
Loading
Loading