cirrus-ci-docs icon indicating copy to clipboard operation
cirrus-ci-docs copied to clipboard

Add example on how to use `matrix` with env vars

Open bartekpacia opened this issue 1 year ago • 5 comments

took me too long to figure this out

bartekpacia avatar Aug 20 '24 22:08 bartekpacia

Hmm, I also expected this to generate 4 tasks, but it generates 16:

blah_task:
  name: Build
  container:
    image: alpine:3.20
  env:
    # Android Command-line tools were obtained with https://stackoverflow.com/a/78890086/7009800
    matrix:
      ANDROID_CLT_VERSION: 9123335 # v8, latest compatible with JDK 8+
      JDK_PACKAGE: openjdk-8-jdk
    matrix:
      ANDROID_CLT_VERSION: 9862592 # v10, latest compatible with JDK 11+
      JDK_PACKAGE: openjdk-11-jdk
    matrix:
      ANDROID_CLT_VERSION: 11479570 # v13, latest compatible with JDK 17+
      JDK_PACKAGE: openjdk-17-jdk
    matrix:
      ANDROID_CLT_VERSION: 11479570 # v13, latest compatible with JDK 17+
      JDK_PACKAGE: openjdk-21-jdk
  info_script:
    - echo "Building Android SDK with Android Command-line tools $ANDROID_CLT_VERSION and JDK $JDK_PACKAGE"

There's an easy workaround in this case though

workaround
blah_task:
  name: Build
  container:
    image: alpine:3.20
  env:
    # Android Command-line tools were obtained with https://stackoverflow.com/a/78890086/7009800
    matrix:
      # v8, latest compatible with JDK 8+
      ANDROID_AND_JDK: 9123335:openjdk-8-jdk

      # v10, latest compatible with JDK 11+
      ANDROID_AND_JDK: 9862592:openjdk-11-jdk

      # v13, latest compatible with JDK 17+
      ANDROID_AND_JDK: 11479570:openjdk-17-jdk

      # v13, latest compatible with JDK 17+
      ANDROID_AND_JDK: 11479570:openjdk-21-jdk
  export_env_vars_script:
    - export ANDROID_CLT_VERSION="$(echo $ANDROID_AND_JDK | cut -d ':' -f1)"
    - export JDK_PACKAGE="$(echo $ANDROID_AND_JDK | cut -d ':' -f2)"
    - echo "ANDROID_CLT_VERSION=$ANDROID_CLT_VERSION" >> $CIRRUS_ENV
    - echo "JDK_PACKAGE=$JDK_PACKAGE" >> $CIRRUS_ENV
  info_script:
    - echo "Building Android SDK with Android Command-line tools $ANDROID_CLT_VERSION and JDK $JDK_PACKAGE"

bartekpacia avatar Aug 20 '24 23:08 bartekpacia

Hmm, I also expected this to generate 4 tasks, but it generates 16

This should work:

blah_task:
  name: Build
  container:
    image: alpine:3.20
  env:
    # Android Command-line tools were obtained with https://stackoverflow.com/a/78890086/7009800
    matrix:
      - ANDROID_CLT_VERSION: 9123335 # v8, latest compatible with JDK 8+
        JDK_PACKAGE: openjdk-8-jdk
      - ANDROID_CLT_VERSION: 9862592 # v10, latest compatible with JDK 11+
        JDK_PACKAGE: openjdk-11-jdk
      - ANDROID_CLT_VERSION: 11479570 # v13, latest compatible with JDK 17+
        JDK_PACKAGE: openjdk-17-jdk
      - ANDROID_CLT_VERSION: 11479570 # v13, latest compatible with JDK 17+
        JDK_PACKAGE: openjdk-21-jdk
  info_script:
    - echo "Building Android SDK with Android Command-line tools $ANDROID_CLT_VERSION and JDK $JDK_PACKAGE"

Regarding the PR itself, perhaps it should use this syntax too.

edigaryev avatar Aug 21 '24 13:08 edigaryev

I think the current way is better to generate 6 tasks - less duplication is involved.

I added another example to make it clear that matrix env vars can be also configured on a fine-grained level, just like you showed in https://github.com/cirruslabs/cirrus-ci-docs/pull/1288#issuecomment-2302111219

bartekpacia avatar Aug 26 '24 16:08 bartekpacia

It seems that the "Spell Check" is failing because granularly is not present in .spelling.

edigaryev avatar Aug 26 '24 17:08 edigaryev

Thanks, fixed.

btw, it seems that the tool used for spellchecking hasn't seen a commit to master in ~4 years, and the latest version is ~7 years old.

bartekpacia avatar Aug 26 '24 17:08 bartekpacia