Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor workflows #190

Merged
merged 16 commits into from
Jul 13, 2020
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
214 changes: 0 additions & 214 deletions .gflows/workflows/ci-build.jsonnet

This file was deleted.

29 changes: 29 additions & 0 deletions .gflows/workflows/ci-build/ci-build.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
local deploy_job = import 'jobs/deploy.libsonnet';
local build_job = import 'jobs/build.libsonnet';
local tests = import 'jobs/tests.libsonnet';
local manifest_check_job = import 'jobs/manifest_check.libsonnet';
local workflows = import '../common/workflows.libsonnet';

local workflow = {
name: "ci-build",
on: workflows.triggers.pull_request_defaults {
push+: {
"paths-ignore": ["deployments/**"],
}
},
env: {
CI: 1,
FORCE_COLOR: 1,
WORKSPACE: "${{ github.workspace }}"
},
jobs: {
build: build_job,
deploy_existing_build: deploy_job.define(false),
deploy_new_build: deploy_job.define(true),
integration_tests: tests.integration_tests,
manifest_check: manifest_check_job,
unit_tests: tests.unit_tests
}
};

std.manifestYamlDoc(workflow)
18 changes: 18 additions & 0 deletions .gflows/workflows/ci-build/jobs/build.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
local steps = import '../../common/steps.libsonnet';
local workflows = import '../../common/workflows.libsonnet';

workflows.ubuntu {
needs: "manifest_check",
"if": "${{ needs.manifest_check.outputs.buildRequired == true }}",
env: {
DOCKER_ACCESS_TOKEN: "${{ secrets.DOCKER_ACCESS_TOKEN }}",
DOCKER_USERNAME: "jbrunton"
},
steps: [
steps.checkout_with_token('CI_ADMIN_ACCESS_TOKEN'),
steps.npm_install,
steps.named('docker login', 'echo "$DOCKER_ACCESS_TOKEN" | docker login -u "$DOCKER_USERNAME" --password-stdin'),
steps.named('build', 'npx ci create build'),
steps.commit('npx ci commit build')
]
}
38 changes: 38 additions & 0 deletions .gflows/workflows/ci-build/jobs/deploy.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
local steps = import '../../common/steps.libsonnet';
local workflows = import '../../common/workflows.libsonnet';

local deploy_steps = [
steps.checkout,
steps.npm_install,
{
id: "payload",
name: "generate payload",
run: "npx ci set-outputs deploy-payload $ENVIRONMENT",
env: {
ENVIRONMENT: "${{ matrix.environment }}",
TASK: "${{ matrix.task }}"
}
},
{
name: "start deployment workflow",
run: "echo \"${PAYLOAD}\" | hub api \"repos/jbrunton/bechdel-lists/deployments\" --input -",
env: {
GITHUB_TOKEN: "${{ secrets.CI_MINION_ACCESS_TOKEN }}",
PAYLOAD: "${{ steps.payload.outputs.payload }}"
}
}
];

{
define(buildRequired):: workflows.ubuntu {
"if": "needs.manifest_check.outputs.deploymentsRequired == true && needs.manifest_check.outputs.buildRequired == %s" % buildRequired,
needs: if buildRequired then [
"manifest_check",
"build"
] else "manifest_check",
steps: deploy_steps,
strategy: {
matrix: "${{ fromJson(needs.manifest_check.outputs.deploymentMatrix) }}"
}
}
}
26 changes: 26 additions & 0 deletions .gflows/workflows/ci-build/jobs/manifest_check.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
local steps = import '../../common/steps.libsonnet';
local workflows = import '../../common/workflows.libsonnet';

workflows.ubuntu {
needs: [
"unit_tests",
"integration_tests"
],
outputs: {
buildRequired: "${{ steps.check.outputs.buildRequired }}",
deploymentMatrix: "${{ steps.check.outputs.deploymentMatrix }}",
deploymentsRequired: "${{ steps.check.outputs.deploymentsRequired }}"
},
steps: [
steps.checkout,
{
id: "check",
"if": "github.event.ref == 'refs/heads/master'",
name: "check manifest",
run: |||
npm install
npx ci set-outputs manifest-checks
|||
}
]
}
37 changes: 37 additions & 0 deletions .gflows/workflows/ci-build/jobs/tests.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
local steps = import '../../common/steps.libsonnet';
local workflows = import '../../common/workflows.libsonnet';

local matrix_strategy = {
matrix: {
service: [
"api",
"client"
]
}
};

{
integration_tests: workflows.ubuntu {
steps: [
steps.checkout,
steps.copy_env,
steps.named("run", "./ci/integration_tests/${SERVICE}.sh") {
env: { SERVICE: "${{ matrix.service }}" }
}
],
strategy: matrix_strategy
},
unit_tests: workflows.ubuntu {
steps: [
steps.checkout,
steps.setup_ruby,
steps.copy_env,
steps.named("run unit tests", "./ci/unit_tests/${SERVICE}.sh") {
env: {
SERVICE: "${{ matrix.service }}"
}
}
],
strategy: matrix_strategy
}
}
Loading