Environment variable expansion in GitHub Workflows - github-actions

Can the existing env variable definition be used to define another env variable?
EXAMPLE (snippet of GH Workflow):
TOP_DOMAIN: com
FQDN: example.${{ env.TOP_DOMAIN }}
What is the preferred way to do this? I know there is a way to do that using GH env files GITHUB_ENV, but more interested if there is some cleaner way without creating a new run step in a workflow.

Related

What does github actions "uses: ./" do?

Does anyone know what this does ?
uses: ./
I see it used in quite a few places but cannot seem to find any reference for it.
The uses keyword of github actions is used to specify the action that should be executed as part of a workflow. The ./ value tells GitHub to use the action defined in the current repository, rather than referencing a pre-built action.
It's also possible to specify the path to the action within the repository, rather than using ./. For example:
steps:
- uses: ./path
with:
parameter1: value1
parameter2: value2
This would execute the action located at ./path within the repository.

GitHub Actions shared non-secret variables

I know about organization-wide secrets for GitHub Actions, but I'm looking for a way to define organization-wide non-secret variables, such as default environment variables or something similar.
Sometimes you simply don't want all your shared config to be secret. An example is for AWS credentials, where it may be beneficial to see the AWS_ACCESS_KEY_ID in plain text, but keep the AWS_SECRET_ACCESS_KEY as a secret.
It seems silly to have to put the same AWS_ACCESS_KEY_ID variable as an env variable in every single repo, while the secret half of that pair works perfectly to configure once for the entire organization... Is there such a way?
Perhaps a workaround could be to create a reused workflow action such as set-env that sets the shared environment variables and then include that in each and every job such as uses: my-org/github-actions/.github/workflows/set-env.yml#main, but it's not the cleanest solution I think.
Too bad there's simply not an option next to GitHub action secrets to allow them to be ... well, not so secret.

How to set global variables like `COMPOSE_FILE` and `IMAGE_NAME` across reusable workflows and custom actions?

In a common CI pattern the following env vars are required by docker compose
COMPOSE_FILE=docker-compose.yml:docker-compose.ci.yml
IMAGE_NAME=ghcr.io/aaa/bbb/ccc:pull_request_identifier
In this supposed setup the docker-compose.ci.yml would define:
services:
someservice:
image: ${IMAGE_NAME}
So COMPOSE_FILE and IMAGE_NAME are required for all interactions with docker compose.
If we want to separate out some parts of our workflow for reuse, this becomes very tedious and copy-paste-y:
Every top-level workflow must define COMPOSE_FILE and IMAGE_NAME, which is duplicative.
Every time we create a custom action that will be called by more than one step, we have to pass both variables every time. And, tediously, we need to run a step to re-echo them out into the $GITHUB_ENV for that step.
A nice little hidden gotcha here is that if you try to use a reusable workflow instead of a custom action, you can't actually pass env vars to it at all, as it's being run in the wrong phase and env vars aren't available.
Is there a way to set COMPOSE_FILE (etc) globally across the workflow and all reusable workflows / custom actions within it?

Azkaban job configuration per environment

I plan to use the Azkaban https://azkaban.github.io/ for running batch jobs. According to CI ideas we have few environments like dev, test, stage, production and of course job should have different configuration for each environment.
According to Azkaban documentation http://azkaban.github.io/azkaban/docs/latest/#job-configuration Azkaban allows for replacing of parameters whenever a ${parameter} is found. And solution looks like:
system.properties
myFlow/
dev.properties
....
prod.properties
foo.job
#system.properties
env=dev
#dev.properties
dev.database=localhost:2181
#prod.properties
prod.database=aws:port
#foo.job
some command --db ${${env}.database}
And later on each environment we can override the env variable. From my point of view this solution looks strange. Can I just say to Azkaban which property file should be used on environment?
What is the best approach to do it?
An other approach can be found here https://github.com/azkaban/azkaban/issues/1545#issuecomment-339750417

CircleCI: env variable depending on branch

Id like to set different value for environment variable in circle.yml depending on branch name.Is it possible?
What i have:
machine:
environment:
MYVAR:"VAL1"
What id like to have is to be able detect type of the branch (master or not) and assign respective value to the variable?
See: Build Details
CIRCLE_BRANCH
The name of the Git branch being tested, e.g. ‘master’, if the build is running for a branch.
so, you can use CIRCLE_BRANCH ENV for detect current branch. After, you can add some logic in code for use MYVAR_xxx or MYVAR_yyy according to CIRCLE_BRANCH.
No, this is not possible using CircleCI due to how shells and environment variables work in our system.
-Ricardo
Developer Evangelist, CircleCI