Github workflow gets invalid when adding a grep command - github

I am trying to run a conditional check before running the run command.
And the docker runs on ubuntu.
runs-on: ubuntu-latest
- name: 'Running checks with test'
if: ${{grep -c 'ApexClass' package/package.xml > 0}}
run: |
echo "Found ApexClass"
- name: 'Running checks without test'
if: ${{grep -c 'ApexClass' package/package.xml < 0}}
run: |
echo "No Apex Found"
And throws an error :
The workflow is not valid. .github/workflows/preDeployCheckQA.yml (Line: 32, Col: 13): Unrecognized named-value: 'grep'. Located at position 1 within expression: grep -c 'ApexClass' package/package.xml > 0 .github/workflows/preDeployCheckQA.yml (Line: 36, Col: 13): Unrecognized named-value: 'grep'. Located at position 1 within expression: grep -c 'ApexClass' package/package.xml < 0
How do I add a check like grep

If this is not supported, I would try and:
define a variable apexcl=$(grep -c 'ApexClass' package/package.xml)
use if in the if conditional
That is:
if: ${{ apexcl != '' }}
run...
if: ${{ apexcl == '' }}
run...

Related

Skip taskB taskC when task A is failed even though conditions of taskB & taskC are met

Q1: I have a single job in ADO YAML pipeline which have 4-5 tasks under steps. I want to trigger those tasks based on few conditions so I've used ADO Expressions. But now i want to skip the taskB when taskA fails. By default it should happen but seems like my task condition is overriding the continueonerror:false
Can you suggest how to do this ?
tried alternative workaround: Multi Job Pipeline setup with 1 task in 1 job & it works fine for us, but want to know how we can setup for multiple tasks in a single job ?
Q2 : Even if i can get taskA status as a variable using REST API & set variable concepts, how can i add multiple conditions in task.something like " variable1=succeeded & variable2 = p1 or variable3 = p2 "
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops
Sample yaml
parameters:
variables:
trigger:
steps:
task: A
continueonerror:false
condition: or(eq(v1, p3), eq(v2, 3), eq(v4, 5))
task: B
continueonerror:false
condition: or(eq(v1, p1), eq(v2, 6))
task: C
continueonerror:false
condition: or(eq(v1, p2), eq(v2, 8))
According to your expectation to skip TaskB if TaskA fails, you may consider adding succeeded() as part of the condition in TaskB together with your other evaluations. Kindly take the following sample YAML for a reference.
trigger: none
parameters:
- name: p1
default: 1
- name: p2
default: 2
- name: p3
default: 3
variables:
v1: 2
v2: 6
v3: 2
v4: 5
steps:
- script: |
echo A
echo "##vso[task.logissue type=error]Simulate task failure."
exit 1
name: TaskA
# continueOnError: true
condition: or(eq(variables['v1'], ${{ parameters.p3 }}), eq(variables['v2'], 3), eq(variables['v4'], 5))
- script: echo B
name: TaskB
condition: and(succeeded(), or(eq(variables['v1'], ${{ parameters.p1 }}), eq(variables['v2'], 6)))
- script: echo C
name: TaskC
condition: and(succeededOrFailed(), or(eq(variables['v1'], ${{ parameters.p2 }}), eq(${{ parameters.p2 }}, 8)))
When TaskA failed the condition evaluation of succeeded() for TaskB would be False; hence TaskB was skipped.
TaskC uses succeededOrFailed() in its condition and will continue to run, even if a previous dependency has failed, unless the run was canceled.
See more information on Specify conditions.

Git actions - simple if statement condition

Hi Please note that the if condition gets executed in the below case even though the variable "highPriority" is zero.
- name: Polaris Result
id: polaris_result
run: |
highPriority=$(cat sample.json | jq '.issueSummary.high')
echo "$highPriority"
echo "::set-output name=highPriority::$highPriority"
- name: fail If crosses threshold for high priority issues
if: ${{ steps.polaris_result.outputs.highPriority }} > 0
run: exit 1
note that echo "$highPriority" outputs "0". However the if condition gets executed in this case which should not be
You should surround all the expression with the { } bracet.
please try:
if: ${{ steps.polaris_result.outputs.highPriority > 0 }}
instead of:
if: ${{ steps.polaris_result.outputs.highPriority }} > 0
See expression section in the doc for some context

boot.img too large when I compile AOSP11 source code for OTA

I trying to enable AB OTA in AOSP11 source code.
Followed below steps:
Step 1:
BOARD_USES_AB_IMAGE := true
Step 2 : CONFIG_ANDROID_AB=y in u boot source code.
Getting below compilation error :
libcameradevice curr board is yy356x
[ 91% 48807/53497] Target boot image from recovery: out/target/product/xx/boot.img
FAILED: out/target/product/xx/boot.img
/bin/bash -c "(out/host/linux-x86/bin/mkbootimg --kernel out/target/product/xx/kernel --ramdis
k out/target/product/xx/ramdisk-recovery.img --cmdline "console=ttyFIQ0 androidboot.baseband=N/
A androidboot.wificountrycode=CN androidboot.veritymode=enforcing androidboot.hardware=yy30board andro
idboot.console=ttyFIQ0 androidboot.verifiedbootstate=orange firmware_class.path=/vendor/etc/firmware i
nit=/init rootwait ro init=/init androidboot.selinux=permissive buildvariant=userdebug" --recovery_dt
bo out/target/product/xx/rebuild-dtbo.img --dtb out/target/product/xx/dtb.img --os_version
11 --os_patch_level 2021-08-05 --second kernel/resource.img --header_version 2 --output out/target/
product/xx/boot.img ) && (size=$(for i in out/target/product/xx/boot.img; do stat -c "%s" "$i" | tr -d '\n'; echo +; done; echo 0); total=$(( $( echo "$size" ) )); printname=$(ec
ho -n " out/target/product/xx/boot.img" | tr " " +); maxsize=$(( 100663296-0)); if [ "
$total" -gt "$maxsize" ]; then echo "error: $printname too large ($total > $maxsize)"; false;
elif [ "$total" -gt $((maxsize - 32768)) ]; then echo "WARNING: $printname approaching size li
mit ($total now; limit $maxsize)"; fi )"
error: +out/target/product/xx/boot.img too large (103485440 > 100663296)
[ 91% 48808/53497] //libcore/mmodules/intracoreapi:art-module-intra-core-api-stubs-source metalava mer
metalava detected access to files that are not explicitly specified. See /home/test/aosp/aa_android/
out/soong/.intermediates/libcore/mmodules/intracoreapi/art-module-intra-core-api-stubs-source/android_
common/art-module-intra-core-api-stubs-source-violations.txt for details.
01:25:09 ninja failed with: exit status 1
failed to build some targets (02:42:20 (hh:mm:ss))

Azure Devops - Matrix Strategy - Conditional Job Run

*please ignore formatting issue
trigger:
- none
parameters:
- name: stg
displayName: "Environment Names"
type: string
pool:
vmImage: ubuntu-latest
stages:
- stage: stage1
displayName: 'Stage C1'
jobs:
- job: jobabc
strategy:
maxParallel: 2
matrix:
env_1:
EnvironmentX: E1
Browser: IE
env_2:
EnvironmentX: E2
Browser: Firefox
env_3:
EnvironmentX: E3
Browser: Chrome
displayName: 'Job 1'
condition: contains('${{parameters.stg}}', $(EnvironmentX))}}
steps:
- task: CmdLine#2
displayName: 'My Task '
inputs:
script: 'echo Stage C1 $(Browser)'
I pass stg parameter as E1E3E4.
In Matrix I have defined EnvironmentX whose value can be E1, E2, or E3.
Below code runs Job 3 times with matrix values defined.
I do NOT want to run all 3 jobs but stg parameter value should decide JOb would run for which matrix values.
Job Condition is NOT working? How to fix this please
You could build the matrix conditionally. Not ideal but that will work:
trigger:
- none
parameters:
- name: stg
displayName: Environment Names
type: string
pool:
vmImage: ubuntu-latest
stages:
- stage: stage1
displayName: 'Stage C1'
jobs:
- job: jobabc
strategy:
maxParallel: 2
matrix:
${{ if contains(parameters.stg, 'E1') }}:
env_1:
EnvironmentX: E1
Browser: IE
${{ if contains(parameters.stg, 'E2') }}:
env_2:
EnvironmentX: E2
Browser: Firefox
${{ if contains(parameters.stg, 'E3') }}:
env_3:
EnvironmentX: E3
Browser: Chrome
displayName: 'Job 1'
steps:
- task: CmdLine#2
displayName: 'My Task '
inputs:
script: 'echo Stage C1 $(Browser)'

GitHub Actions: Can't set env variable

I am trying to set a simple environment variable based on the branch name, but I cannot get it to work. Based on the logs, the env var seems to be set correctly, but it is still empty afterwards:
TF_VAR_project_name=staging >> /home/runner/work/_temp/_runner_file_commands/set_env_51dc1c8d-60b9-47bd-b91e-f315cd9349a7
--
name: "Terraform"
on:
push:
branches:
- main
- staging
pull_request:
jobs:
terraform:
name: "Terraform"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Get branch names
id: branch-name
uses: tj-actions/branch-names#v4
- name: For PR, get base ref branch name
if: github.event_name == 'pull_request'
run: |
echo "TF_VAR_project_name=${{ steps.branch-name.outputs.base_ref_branch }} >> $GITHUB_ENV"
- name: For push, get current branch name
if: github.event_name == 'push'
run: |
echo "TF_VAR_project_name=${{ steps.branch-name.outputs.current_branch }} >> $GITHUB_ENV"
- name: Test1
run: |
echo "$TF_VAR_project_name"
- name: Set is prod based on the branch
run: |
echo "TF_VAR_is_prod=$(( $TF_VAR_project_name == prod ? true : false ))" >> $GITHUB_ENV
Complete Log:
Thanks!
There are two syntax problems with your workflow:
FIRST:
The syntax used to set variables has " incorrectly used:
run: |
echo "TF_VAR_project_name=${{ steps.branch-name.outputs.base_ref_branch }} >> $GITHUB_ENV"
Should be:
run: |
echo "TF_VAR_project_name=${{ steps.branch-name.outputs.base_ref_branch }}" >> $GITHUB_ENV
Before the >> $GITHUB_ENV (documentation reference)
SECOND:
The syntax used at the last step uses $(( ... )) instead of ${{ .. }}:
- name: Set is prod based on the branch
run: |
echo "TF_VAR_is_prod=$(( $TF_VAR_project_name == prod ? true : false ))" >> $GITHUB_ENV
Should be:
- name: Set is prod based on the branch
run: |
echo "TF_VAR_is_prod=${{ $TF_VAR_project_name == prod ? true : false }}" >> $GITHUB_ENV
As you used on other steps.