The following is a github workflow I’m using to build a project and get git commit SHA’s and tags:
name: proj-build
on: [workflow_call, workflow_dispatch]
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
CYGWIN_HOME: C:cygwin64
PERL_HOME: C:strawberry-perlperl
CMAKE_BUILD_ARTIFACT_NAME: artifact-build
COMMIT_SHA: ''
TAG_NAME: ''
jobs:
build-cmake:
runs-on: [ self-hosted, Windows ]
timeout-minutes: 500
steps:
# Authenticate for accessing repos in the organization
- name: Setup git
uses: myorg/common-actions/setup-git@master
id: setup-git
with:
app-id: ${{ vars.IRA_APP_ID }}
private-key: ${{ secrets.IRA_PRIVATE_KEY }}
- name: Checkout proj repo
uses: actions/checkout@v4
with:
token: ${{ steps.setup-git.outputs.token }}
fetch-tags: 'true'
fetch-depth: 0
path: myproj
- name: Get Commit SHA
id: get-sha
shell: pwsh
run: |
Write-Output "SHA=${{ github.sha }}"
echo "COMMIT_SHA=${{ github.sha }}" >> $GITHUB_ENV
- name: Get Tag
id: get-tag
shell: pwsh
continue-on-error: true
if: startsWith(github.ref, 'refs/tags/')
run: |
Write-Output "TAG=${{ github.ref }}"
$tagName = "${{ github.ref }}" -replace 'refs/tags/', ''
Write-Output "tagName=$tagName"
echo "TAG_NAME=$tagName" >> $GITHUB_ENV
- name: Handle untagged commits
shell: pwsh
if: env.TAG_NAME == ''
run: echo "TAG_NAME=none" >> $GITHUB_ENV
- name: Verify commit & tag info in the environment
id: set-outputs
shell: pwsh
run: |
Write-Output "COMMIT_SHA=${{ env.COMMIT_SHA }}"
Write-Output "TAG_NAME=${{ env.TAG_NAME }}"
- name: Listing contents of repo directory before CMake build
shell: powershell
run: |
cd ${{ github.workspace }}myproj.githubworkflows
. ./get-contents.ps1
Write-Output "Getting the contents of the myproj repo directory before CMake build..."
Get-Directory-Contents -Path ${{ github.workspace }}myproj
- name: Build myproj
shell: cmd
run: |
set PATH=%PATH%;%CYGWIN_HOME%
cd ${{ github.workspace }}myproj
cmake -S . -B build
cmake --build build --target install
- name: Listing contents of repo directory after CMake build
shell: powershell
run: |
cd ${{ github.workspace }}myproj.githubworkflows
. ./get-contents.ps1
Write-Output "Getting the contents of the myproj repo directory after CMake build..."
Get-Directory-Contents -Path ${{ github.workspace }}myproj
- name: Creating an info file for build directory
shell: powershell
run: |
tree ${{ github.workspace }}myprojbuild | `
Out-File -FilePath ${{ github.workspace }}myprojbuildbuild.info -Append -Encoding utf8; `
Get-ChildItem ${{ github.workspace }}myprojbuild -Recurse | `
Measure-Object -Property Length -Sum | ForEach-Object { 'Total Size: {0} MB' -f ($_.Sum / 1MB) } | `
Out-File -FilePath ${{ github.workspace }}myprojbuildbuild.info -Append -Encoding utf8
- name: Save environment variables to file
shell: cmd
run: |
echo COMMIT_SHA=${{ env.COMMIT_SHA }}
echo TAG_NAME=${{ env.TAG_NAME }}
echo COMMIT_SHA=${{ env.COMMIT_SHA }} > ${{ github.workspace }}myprojbuildenvironment.info
echo TAG_NAME=${{ env.TAG_NAME }} >> ${{ github.workspace }}myprojbuildenvironment.info
echo %COMMIT_SHA%
echo %TAG_NAME%
- name: Upload Artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: ${{ env.CMAKE_BUILD_ARTIFACT_NAME }}
retention-days: 2
path: |
${{ github.workspace }}myprojbuild
I would like use the environment variables stored in a .info file that’ll be uploaded as artifact to be used by subsequent workflows. However, the steps Verify commit & tag info in the environment and Save environment variables to file give blank outputs as
COMMIT_SHA=
TAG_NAME=
Can this be fixed? What exactly am I doing wrong?