Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access output of sbt print in Github Actions workflow

I'm trying to save the output of running sbt print version | tail -n 1 to an environment variable in a Github Actions workflow, and it doesn't seem to work.

This is what I think should work, but it's just an empty string, when I try to access the variable later on in the job:

echo "TAG_VERSION=$(sbt 'print version' | tail -n 1)" >> $GITHUB_ENV

It works great in my own shell, but not in Github Actions.

I'm using version 1.5.3for sbt.

This is the logs for the step that doesn't seem to work, test version step, it just seems to not load up correctly.:

Run echo "TAG_VERSION=$(sbt 'print version' | tail -n 1)" >> $GITHUB_ENV
  echo "TAG_VERSION=$(sbt 'print version' | tail -n 1)" >> $GITHUB_ENV
  shell: /usr/bin/bash -e {0}
  env:
    CI: true
    JAVA_HOME: /home/runner/.jabba/jdk/[email protected]
Downloading sbt launcher for 1.5.3:
  From  https://repo1.maven.org/maven2/org/scala-sbt/sbt-launch/1.5.3/sbt-launch-1.5.3.jar
    To  /home/runner/.sbt/launchers/1.5.3/sbt-launch.jar
Downloading sbt launcher 1.5.3 md5 hash:
  From  https://repo1.maven.org/maven2/org/scala-sbt/sbt-launch/1.5.3/sbt-launch-1.5.3.jar.md5
    To  /home/runner/.sbt/launchers/1.5.3/sbt-launch.jar.md5
[info] [launcher] getting org.scala-sbt sbt 1.5.3  (this may take some time)...
[info] [launcher] getting Scala 2.12.14 (for sbt)...

This is the full workflow:

name: CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]
  workflow_dispatch:
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: olafurpg/setup-scala@v11
      #- name: run tests
       # run: |
        #  sbt test
      - name: docker login
        run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
      #- name: build image and publish
      #  run: sbt 'Docker / publish'
      - name: test version
        run: echo "TAG_VERSION=$(sbt 'print version' | tail -n 1)" >> $GITHUB_ENV
      - name: print test version
        run: echo ${{ env.TAG_VERSION }}
      - name: get version
        run: echo "TAG_VERSION=$(echo $(sbt -Dsbt.supershell=false 'print version' | tail -n 1))" >> $GITHUB_ENV
      - name: checkout helm repo
        uses: actions/checkout@v2
        with:
          repository: peterstorm/dialer-integration-argo
          token: ${{ secrets.ACCESS_TOKEN }}
          path: './dialer-integration-argo'
      - name: change image tag in helm repo
        uses: mikefarah/yq@master
        with:
          cmd: yq eval -i '.image.tag = "${{ env.TAG_VERSION }}"' './dialer-integration-argo/values.yaml'
      - name: push helm repo changes
        run: |
          cd dialer-integration-argo &&
          git config --global user.name 'Peter Storm' &&
          git config --global user.email '[email protected]' &&
          git add . &&
          git commit -m "commit from github actions" &&
          git push origin master

Thank you!

like image 912
Peter Storm Avatar asked Oct 28 '25 05:10

Peter Storm


1 Answers

Hopefully, someone else finds this to be helpful (I know the question is over a year-old, but you never know). I had very similar issue, and was attempting to output the result of $(sbt 'print version' | tail -n 1) to a gha step output or the $GITHUB_ENV. After many different permutations I found success by setting the -no-colors flag on the sbt command so:

- name: Get Version
  id: version
  run: echo ::set-output name=snapshot::$(sbt -no-colors 'print version' | tail -n 1)
- name: Show Version
  run: echo $(sbt -no-colors 'print version' | tail -n 1)
- name: Output Version
  run: echo "${{ steps.version.outputs.snapshot }} :rocket:" >> $GITHUB_STEP_SUMMARY

I would guess this would work if you used the $GITHUB_ENV mechanism

like image 75
Ahmad Ragab Avatar answered Oct 30 '25 13:10

Ahmad Ragab