CircleCI reports "No workflow" when creating a tagged release - circleci

I want to build a CircleCI workflow which builds and pushes to ECR only when I create a tagged release in Github.
I have the following CircleCI workflow:
workflows:
test-build-and-push-image:
jobs:
- get_python_dependencies
- unit_tests:
requires:
- get_python_dependencies
- aws-ecr/build-and-push-image:
name: build-and-push-to-ecr
repo: ${CIRCLE_PROJECT_REPONAME}
tag: ${CIRCLE_SHA1}
create-repo: true
requires:
- unit_tests
filters:
tags:
only: /.*/
branches:
ignore: /.*/
As I understand it, the filters on build-and-push-to-ecr are supposed to mean:
Run this job for any tag whatsoever
Don't run this job when pushing to any branch
But when I create a tagged release I get:
Why aren't my filters working?

A very close reading of the docs under Executing workflows for a git tag reveals a well-hidden detail:
if a job requires any other jobs (directly or indirectly), you must use regular expressions to specify tag filters for those jobs.
In other words, every job in the workflow must have the same filters for the build and push job to happen.
We can keep things a bit DRYer using & anchors:
workflows:
test-build-and-push-image:
jobs:
- get_python_dependencies:
filters: &tagged
# We only want to trigger this workflow on tags, not pushes to branches.
branches:
ignore: /.*/
tags:
# Trigger on every tag
only: /.*/
- unit_tests:
requires:
- get_python_dependencies
<<: *tagged
- aws-ecr/build-and-push-image:
name: build-and-push-to-ecr
repo: ${CIRCLE_PROJECT_REPONAME}
tag: ${CIRCLE_SHA1}
create-repo: true
requires:
- unit_tests
<<: *tagged

Related

Chromatic deployment error when using github-actions

I am working on a React project which is using storybook, I'm trying to publish this storybook into chromatic with GitHub actions. I am using their sample chromatic.yml with just a few changes to match my project needs. Running the chromatic-cli my storybook is desployed succesflly but when I use GitHub actions the following error is displayed:
Error: ✖ Failed to collect Storybook metadata
Could not find a supported Storybook viewlayer package. Make sure one is installed, or set CHROMATIC_STORYBOOK_VERSION.
Here's the full error log:
Run chromaui/action#v1
with:
projectToken: ***
Chromatic CLI v5.7.0
https://www.chromatic.com/docs/cli
Authenticating with Chromatic
→ Connecting to https://index.chromatic.com
Authenticated with Chromatic
→ Using project token '********119f'
Retrieving git information
Retrieved git information
→ Commit 'a9f9af7' on branch 'master'; found 1 baseline commit
Collecting Storybook metadata
→ Could not find a supported Storybook viewlayer package. Make sure one is installed, or set CHROMATIC_STORYBOOK_VERSION.
✖ Failed to collect Storybook metadata
Could not find a supported Storybook viewlayer package. Make sure one is installed, or set CHROMATIC_STORYBOOK_VERSION.
→ View the full stacktrace below
If you need help, please chat with us at https://www.chromatic.com/docs/cli for the fastest response.
You can also email the team at support#chromatic.com if chat is not an option.
Please provide us with the above CLI output and the following info:
{
"timestamp": "2021-04-23T22:03:58.789Z",
"sessionId": "2f736280-50df-4f2e-aa3d-00d90236cf61",
"gitVersion": "2.31.1",
"nodePlatform": "linux",
"nodeVersion": "12.13.1",
"packageName": "chromatic",
Error: non-zero exit code
"packageVersion": "5.7.0",
"flags": {
"projectToken": "***",
"fromCI": true,
"interactive": false,
"exitZeroOnChanges": true,
"exitOnceUploaded": false,
"allowConsoleErrors": false
},
"buildScript": "build-storybook",
"errorType": "Error",
"errorMessage": "✖ Failed to collect Storybook metadata"
}
Error: ✖ Failed to collect Storybook metadata
Could not find a supported Storybook viewlayer package. Make sure one is installed, or set CHROMATIC_STORYBOOK_VERSION.
at /home/runner/work/_actions/chromaui/action/v1/bin/lib/getStorybookInfo.js:83:11
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async getStorybookInfo (/home/runner/work/_actions/chromaui/action/v1/bin/lib/getStorybookInfo.js:115:25)
at async setStorybookInfo (/home/runner/work/_actions/chromaui/action/v1/bin/tasks/storybookInfo.js:6:42)
at async Task.task (/home/runner/work/_actions/chromaui/action/v1/bin/lib/tasks.js:13:7)
And this is my chromatic.yml
# Workflow name
name: "Chromatic Deployment"
# Event for the workflow
on:
push:
branches: [master, stagging, developing]
pull_request:
branches: [master, stagging, developing]
# List of jobs
jobs:
test:
# Operating System
runs-on: ubuntu-latest
defaults:
run:
working-directory: foo
# Job steps
steps:
- uses: actions/checkout#v1
- run: yarn
#👇 Adds Chromatic as a step in the workflow
- uses: chromaui/action#v1
# Options required for Chromatic's GitHub Action
with:
#👇 Chromatic projectToken, see https://storybook.js.org/tutorials/intro-to-storybook/react/en/deploy/ to obtain it
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
So here's what I found on chromatic's official repository:
https://github.com/chromaui/chromatic-cli/issues/227
https://github.com/chromaui/chromatic-cli/issues/324
https://github.com/chromaui/chromatic-cli/issues/197
There's a chance this problem originates from the fact I'm using a monorepo, I though using working-directory was enough to fix this but there an aditional parameter to be used chromaui, workinDir.
Here's my current chromatic.yml
# Workflow name
name: "Chromatic Deployment"
# Event for the workflow
on:
push:
branches: [master, stagging, developing]
pull_request:
branches: [master, stagging, developing]
# List of jobs
jobs:
chromatic-deployment:
# Operating System
runs-on: ubuntu-latest
defaults:
run:
working-directory: foo
# Job steps
steps:
- uses: actions/checkout#v1
- run: yarn
#👇 Adds Chromatic as a step in the workflow
- uses: chromaui/action#v1
# Options required for Chromatic's GitHub Action
with:
workingDir: foo
projectToken: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}

Executing a CircleCI job only when tag matches a certain pattern

I have the following workflow definition for a CircleCI build
workflows:
version: 2
default:
jobs:
- verify
- tests_3_1:
requires:
- verify
- tests_5_0:
requires:
- verify
- pack:
requires:
- tests_3_1
- tests_5_0
- push:
requires:
- pack
context:
- GitHub
filters:
tags:
only: /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
branches:
ignore: /.*/
The idea is to:
run verify, test_3_1, test_5_0, pack on all commits
on top of the jobs above, run the job push when on master and with a tag that matches a semver version prepended by a v
For some reason no build is triggered when the commit is tagged. I am not sure if the problem is in the filter or in the regex not matching the build tags.
For now I tried v0.1.0-preview-0001 which matches on RegexPal.
Could you suggest any improvement? I see there is this question that is pretty similar but I have issues implementing the suggested solution
I solved this by specifying a tag regex filter for every job before push as shown in the documentation.
workflows:
version: 2
default:
jobs:
- verify:
filters:
tags:
only: /.*/
- tests_3_1:
requires:
- verify
filters:
tags:
only: /.*/
- tests_5_0:
requires:
- verify
filters:
tags:
only: /.*/
- pack:
requires:
- tests_3_1
- tests_5_0
filters:
tags:
only: /.*/
- push:
requires:
- pack
context:
- GitHub
filters:
tags:
only: /^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
branches:
ignore: /.*/

Conditionally setting parameter in yml file (Azure pipeline): VAR not updating

Problem
I want to set a parameter conditionally based on which branch triggered the pipeline. If the triggered branch was feature/automated-testing, I would like to set a parameter equal to "True". See the code below.
Parts of my pipeline.yml file looks like so:
trigger:
branches:
include:
- feature/automated-testing
...
# Global variables for the pipeline
variables:
- name: "triggerRepoName"
value: "$(Build.SourceBranchName)"
stages:
# common stage. Docker build, tag and push
- stage: BuildDockerImage
displayName: "Build docker image"
variables:
...
jobs:
- template: /templates/pipelines/my-prject.yml#templates
parameters:
${{ if eq( variables.triggerRepoName, 'feature/automated-testing') }}:
runTests: "True"
${{ if ne(variables.triggerRepoName, 'feature/automated-testing') }}:
runTests: "False"
Question
When I push from branch feature/automated-testing and ´echo´ the variable runTests in the Dockerfile, it is blank. Is there something wrong with my syntax in the conditional statement?
I believe the error is in the way the variable is set conditionally, and I have therefore chosen not to supply the Dockerfile nor the other .yml template .yml used.
Please change variables.triggerRepoName to variables['triggerRepoName']. It should solve your issue.

How do we conditionally run a CircleCI workflow?

I have followed the guide described in Conditional steps in jobs and conditional workflows and written the below code for my CircleCI pipeline.
version: 2.1
workflows:
version: 2.1
workflowone:
when:
condition: false
jobs:
- samplejob:
workflowtwo:
when:
condition: true
jobs:
- jobone
jobs:
samplejob:
docker:
- image: buildpack-deps:stable
steps:
- run:
name: Sample Job in WF 1
command: |
echo "This job is in workflowone and the workflow should not run"
jobone:
docker:
- image: buildpack-deps:stable
steps:
- run:
name: Sample Job in WF 2
command: |
echo "This job is in workflowtwo and the workflow should run"
When I run the above code the output is not what is expected. First workflow should not run because the condition is false. Both worflows start running when the pipeline in triggered. Can anyone point out the missing piece here?
According to the CircleCI docs, workflows (specifically) does not accept the condition key:
Note: When using logic statements at the workflow level, do not
include the condition: key (the condition key is only needed for job
level logic statements).
See here logic-statement-examples (scroll to the bottom of this section to see the note)

When condition on Circleci 2.1 does not work

Recently I've made some configuration on my team's github circleci. I needed to use a when statement to devide ci logics. I referenced this document(https://circleci.com/docs/2.0/configuration-reference/#logic-statements) but it seems the document not correct.
Below is my step definition:
...
image_build_step:
executor: golang_executor
steps:
- checkout
- setup_remote_docker:
version: 18.09.3
docker_layer_caching: true
- define_svc_name:
jobname: ${CIRCLE_JOB} # On this step set $SVC variable
- when:
conditon:
equal: ["${SVC}", "SVC_A" ]
- aws-ecr/build-and-push-image:
repo: SVC_A_REPO
dockerfile: ./Dockerfile
tag: "latest,${CIRCLE_SHA1},build-${CIRCLE_BUILD_NUM}"
...
Also I already tried this.
...
image_build_step:
executor: golang_executor
steps:
- checkout
- setup_remote_docker:
version: 18.09.3
docker_layer_caching: true
- define_svc_name:
jobname: ${CIRCLE_JOB} # On this step set $SVC variable
- when:
equal: ["${SVC}", "SVC_A" ]
- aws-ecr/build-and-push-image:
repo: SVC_A_REPO
dockerfile: ./Dockerfile
tag: "latest,${CIRCLE_SHA1},build-${CIRCLE_BUILD_NUM}"
...
I cannot figure out my mistake using when statement on circleci. Additionaly, I already passed circleci config validate .circleci/config.yaml command before I pushed this commit.
What is the correct usage of when statement in circleci? Joining circleci forum is also annoying me using github account, so I leave my question on stakeoverflow.
It's not possible to use environment variables in logic statements. The reason is that logic statements are evaluated at configuration compilation time, whereas environment variables are interpolated at run time.
The only workaround I know of is to use the CircleCI dynamic configuration functionality to set pipeline parameters' values in the "setup workflow" that you then pass to the "continuation" workflow.

Resources