Skip to content

Commit

Permalink
[com.circleci.v2] Support specifying custom job-level parameters whil…
Browse files Browse the repository at this point in the history
…e calling a job in a workflow (#86)

So far there was no way to specify these custom parameters while calling a workflow job. This allows user to specify custom `parameters` while invoking a WorkflowJob.
  • Loading branch information
yyuu authored Dec 9, 2024
1 parent 0b01a8d commit 29d5506
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 1 deletion.
11 changes: 11 additions & 0 deletions packages/com.circleci.v2/Config.pkl
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,15 @@ class WorkflowJob {

/// Job Filters can have the key branches or tags
filters: JobFilters?

/// Supplemental job-level parameters to be specified when
/// [calling a `job` in `workflow`](https://circleci.com/docs/configuration-reference/#jobs-in-workflow).
///
/// There are several reserved parameter names that cannot be used from CircleCI users.
hidden parameters: Mapping<
String(!(this is "name"|"context"|"filters"|"matrix"|"requires"|"type")),
*Listing<Step>|String|Number|Boolean
>?
}

class JobFilters {
Expand Down Expand Up @@ -786,6 +795,8 @@ output {
if (it.hasProperty("__name__"))
Map(it.__name__, it.toMap().remove("__name__"))
else it
[WorkflowJob] = (it) ->
it.toMap() + (it.parameters ?? Map()).toMap()
}
}
}
2 changes: 1 addition & 1 deletion packages/com.circleci.v2/PklProject
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
amends "../basePklProject.pkl"

package {
version = "1.2.0"
version = "1.3.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//===----------------------------------------------------------------------===//
// Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//===----------------------------------------------------------------------===//
amends ".../Config.pkl"
// Adaptation of https://github.com/CircleCI-Public/aws-ecr-orb/blob/v9.3.7/src/examples/build_and_push_image_w_registry_login.yml#L21-L36

version = "2.1"

orbs {
["aws-ecr"] = "circleci/[email protected]"
["aws-cli"] = "circleci/[email protected]"
}

workflows {
["build-and-push-image-with-container-registry-login"] {
jobs {
new {
["aws-ecr/build_and_push_image"] {
parameters {
["container_registry_login"] = true
["registry_login"] {
module.run("docker login -u ${HEROKU_USERNAME} -p ${HEROKU_API_KEY}")
module.run("docker login -u ${GITHUB_USERNAME} -p ${GITHUB_TOKEN}")
module.run("docker login -u ${DOCKERHUB_ID} -p ${DOCKERHUB_PASSWORD}")
}
["auth"] {
(module.OrbStep("aws-cli/setup")) {
role_arn = "arn:aws:iam::123456789012"
}
}
["repo"] = "my-sample-repo"
["tag"] = "sampleTag"
["dockerfile"] = "Dockerfile"
["path"] = "."
["region"] = "us-west-2"
}
}
}
}
}
}
30 changes: 30 additions & 0 deletions packages/com.circleci.v2/tests/Config.pkl-expected.pcf
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
examples {
["build_and_push_image_w_registry_login.yaml"] {
"""
# Generated from CircleCI.pkl. DO NOT EDIT.
version: '2.1'
orbs:
aws-ecr: circleci/[email protected]
aws-cli: circleci/[email protected]
workflows:
build-and-push-image-with-container-registry-login:
jobs:
- aws-ecr/build_and_push_image:
container_registry_login: true
registry_login:
- run:
command: docker login -u ${HEROKU_USERNAME} -p ${HEROKU_API_KEY}
- run:
command: docker login -u ${GITHUB_USERNAME} -p ${GITHUB_TOKEN}
- run:
command: docker login -u ${DOCKERHUB_ID} -p ${DOCKERHUB_PASSWORD}
auth:
- aws-cli/setup:
role_arn: arn:aws:iam::123456789012
repo: my-sample-repo
tag: sampleTag
dockerfile: Dockerfile
path: '.'
region: us-west-2

"""
}
["concurrent_workflow.yaml"] {
"""
# Generated from CircleCI.pkl. DO NOT EDIT.
Expand Down

0 comments on commit 29d5506

Please sign in to comment.