Skip to content

Idea: add a pre-step, post-step parameters #25

@compojoom

Description

@compojoom

Feature Request

Currently we are using this orb, but it somewhat difficult to inject code in the jobs. Because we cannot inject code in the jobs, we have to create our own jobs that are copy of the orb's job with one or 2 steps in between.

Here is an example. I need to use the rn/android_build job, but on our circleci java was failing so I had to make modifications to the executor and I also needed to generate the keystore files out of the circleci env variables and I also needed to set some bash env. variables. My job looks like this:

  app_android_build:
    executor:
      name: rn/linux_android
      gradle_options: '-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -Dorg.gradle.caching=true -Dorg.gradle.configureondemand=true -Dkotlin.compiler.execution.strategy=in-process -Dkotlin.incremental=false'
      java_options: '-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8'
      build_threads: 2
    parameters:
      project_path:
        description: The path to the root of the Android project you want to build, relative to the root of the repository.
        type: string
        default: "./android"
      build_type:
        description: The build type to build. This is normally either "debug" or "release" but you may have custom build types configured for your app.
        type: string
        default: "debug"
      store_artifacts:
        description: Store this job store files as job artifacts? Defaults to true
        type: boolean
        default: true
      persist_to_workspace:
        description: Should this job persist files to a workspace? Defaults to true
        type: boolean
        default: true
    steps:
      - checkout
      - attach_workspace_and_run_yarn
      - run:
          name: "Decode android keys"
          command: |
            echo $ANDROID_KEYSTORE_RELEASE_BASE64 | base64 -d > $HOME/project/keyfiles/release-key.keystore
            echo $ANDROID_KEYSTORE_DEVELOP_BASE64 | base64 -d > $HOME/project/keyfiles/develop-key.keystore
      - run:
          name: "Create Set Gradle variables"
          command: |
            echo 'export RN_SRC_EXT=e2e.js' >> $BASH_ENV
            echo 'export ORG_GRADLE_PROJECT_MYAPP_RELEASE_STORE_FILE=$MYAPP_RELEASE_STORE_FILE' >> $BASH_ENV
            echo 'export ORG_GRADLE_PROJECT_MYAPP_RELEASE_KEY_ALIAS=$MYAPP_RELEASE_KEY_ALIAS' >> $BASH_ENV
            echo 'export ORG_GRADLE_PROJECT_MYAPP_RELEASE_STORE_PASSWORD=$MYAPP_RELEASE_STORE_PASSWORD' >> $BASH_ENV
            echo 'export ORG_GRADLE_PROJECT_MYAPP_RELEASE_KEY_PASSWORD=$MYAPP_RELEASE_KEY_PASSWORD' >> $BASH_ENV
            source $BASH_ENV
      - rn/android_build:
          build_type: <<parameters.build_type>>
          project_path: <<parameters.project_path>>
      - when:
          condition: <<parameters.persist_to_workspace>>
          steps:
            - persist_to_workspace:
                root: .
                paths:
                  - <<parameters.project_path>>/app/build/outputs/apk
      - when:
          condition: <<parameters.store_artifacts>>
          steps:
            - store_artifacts:
                path: <<parameters.project_path>>/app/build/outputs/apk

It works, but it is copy/paste and it drives me nuts. Today I saw the pre-steps and post-steps that circleci offers for workflows.

I tried to use the pre-step to generate the keystore file, but the pre-step is run way too early - before the workspace is attached.

So I was thinking - how about defining a pre-steps/on_after_initialize command ourselves?
It could be something simple like this:

      - when:
          condition: <<parameters.on_after_initialize>>
          steps:
            - run:
                name: "custom command"
                command: <<parameters.on_after_initialize_command>>

What do you guys think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions