CIRCLE_BRANCH to lowercase

Hi! When publishing release channels to expo other than master, the branch name is chosen as CIRCLE_BRANCH. The problem is that all our branch names has some uppercase letters. We then get an error saying that the release channels only can have lowercase letters. I have tried to convert the CIRCLE_BRANCH value to lowercase, but it does not seem to be exported in lowercase in the EXPO_RELEASE_CHANNEL. Is it possible to change the CIRCLE_BRANCH value?

version: 2
publish: &publish
working_directory: ~/native
docker:
- image: cimg/node:14.17.2
steps:
- checkout
- restore_cache:
name: Restore yarn package cache
key: v1-cache-dependencies-{{ checksum “yarn.lock” }}-{{ checksum “package.json” }}-{{ arch }}
- run:
name: Install dependencies
command: yarn install --frozen-lockfile
- save_cache:
name: Save yarn package cache
paths:
- ~/.cache/yarn
key: v1-cache-dependencies-{{ checksum “yarn.lock” }}-{{ checksum “package.json” }}-{{ arch }}
- run:
name: Login to Expo
command: (yes || true ) | sudo npx expo login -u $EXPO_USERNAME -p $EXPO_PASSWORD
- run:
name: Save current branch name to an env variable
command: |
if [ “${CIRCLE_BRANCH}” == “master” ]; then
echo ‘export EXPO_RELEASE_CHANNEL=“default”’ >> $BASH_ENV
else
echo ‘export EXPO_RELEASE_CHANNEL=${CIRCLE_BRANCH}’ >> $BASH_ENV
fi
- run:
name: Publish to Expo
command: |
sudo npx expo publish --non-interactive --max-workers 1 --release-channel $EXPO_RELEASE_CHANNEL

jobs:
build_and_test:
docker:
- image: cimg/node:14.17.2
steps:
- checkout
- restore_cache:
name: Restore yarn package cache
key: v1-cache-dependencies-{{ checksum “yarn.lock” }}-{{ checksum “package.json” }}-{{ arch }}
- run:
name: Install dependencies
command: yarn install --frozen-lockfile
- save_cache:
name: Save yarn package cache
paths:
- ~/.cache/yarn
key: v1-cache-dependencies-{{ checksum “yarn.lock” }}-{{ checksum “package.json” }}-{{ arch }}
- run:
name: Run tests
command: yarn test
- run:
name: Run linting
command: yarn lint

publish_to_expo:
<<: *publish

workflows:
version: 2
workflow:
jobs:
- build_and_test
- publish_to_expo:
filters:
branches:
ignore: gh-pages

Hi there,

If I’m following you correctly I think all you need to do is use Bash 4’s case expansion, specifically ${parameter,,}.

$ docker run --rm -it cimg/node:14.17.2 bash
circleci@7562d869e7a8:~/project$ CIRCLE_BRANCH=fooBarBaTT
circleci@7562d869e7a8:~/project$ printf '%s\n' "${CIRCLE_BRANCH}" "${CIRCLE_BRANCH,}" "${CIRCLE_BRANCH,,}" "${CIRCLE_BRANCH^}" "${CIRCLE_BRANCH^^}"
fooBarBaTT
fooBarBaTT
foobarbatt
FooBarBaTT
FOOBARBATT
circleci@7562d869e7a8:~/project$ printf '%s\n' "${CIRCLE_BRANCH,,}"
foobarbatt

IIUC you can probably just put that directly in your command rather than using the BASH_ENV feature.

Does that help?

2 Likes