How to ensure that Makefile/shell script vars are exported

Hello,

Sorry if asking naive question.

I’m running basic steps as below, which runs Makefile targets. During that Makefile execution, there are some env vars that need to be defined but they are not getting exported, which normally works if I run it locally.
Example:

RELEASE_TAG ?= $(shell git describe --abbrev=0 2>/dev/null)
RELEASE_DIR := out
RELEASE_NOTES_DIR := releasenotes
PREVIOUS_TAG ?= $(shell git tag -l | grep -B 1 $(RELEASE_TAG) | head -n 1)

Then I moved those steps to a shell scripts, and still variable population is not happening only when executed by GitHub actions. Is there something I’m missing?

on:
  push:
    # Sequence of patterns matched against refs/tags
    tags:
    - "v0.*.*"

name: Release

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: checkout code
        uses: actions/checkout@v2
      - name: Install go
        uses: actions/setup-go@v2
        with:
          go-version: '1.16'
      - name: Generate release artifacts and notes
        run: |
          make release
      - name: Release
        uses: softprops/action-gh-release@v1
        with:
          draft: true
          files: out/*
          body_path: releasenotes/releasenotes.md

make[1]: Entering directory '/home/runner/work/cluster-api-provider-metal3/cluster-api-provider-metal3'

[27](https://github.com/fmuyassarov/cluster-api-provider-metal3/runs/3802595227?check_suite_focus=true#step:4:27)./release.sh

[28](https://github.com/fmuyassarov/cluster-api-provider-metal3/runs/3802595227?check_suite_focus=true#step:4:28)++ git describe --abbrev=0

[29](https://github.com/fmuyassarov/cluster-api-provider-metal3/runs/3802595227?check_suite_focus=true#step:4:29)+ export RELEASE_TAG=

[30](https://github.com/fmuyassarov/cluster-api-provider-metal3/runs/3802595227?check_suite_focus=true#step:4:30)+ RELEASE_TAG=

[31](https://github.com/fmuyassarov/cluster-api-provider-metal3/runs/3802595227?check_suite_focus=true#step:4:31)+ export RELEASE_DIR=out

[32](https://github.com/fmuyassarov/cluster-api-provider-metal3/runs/3802595227?check_suite_focus=true#step:4:32)+ RELEASE_DIR=out

[33](https://github.com/fmuyassarov/cluster-api-provider-metal3/runs/3802595227?check_suite_focus=true#step:4:33)+ export RELEASE_NOTES_DIR=releasenotes

[34](https://github.com/fmuyassarov/cluster-api-provider-metal3/runs/3802595227?check_suite_focus=true#step:4:34)+ RELEASE_NOTES_DIR=releasenotes

[35](https://github.com/fmuyassarov/cluster-api-provider-metal3/runs/3802595227?check_suite_focus=true#step:4:35)++ git tag -l

[36](https://github.com/fmuyassarov/cluster-api-provider-metal3/runs/3802595227?check_suite_focus=true#step:4:36)++ grep -B 1

[37](https://github.com/fmuyassarov/cluster-api-provider-metal3/runs/3802595227?check_suite_focus=true#step:4:37)++ head -n 1

[38](https://github.com/fmuyassarov/cluster-api-provider-metal3/runs/3802595227?check_suite_focus=true#step:4:38)Usage: grep [OPTION]... PATTERNS [FILE]...

[39](https://github.com/fmuyassarov/cluster-api-provider-metal3/runs/3802595227?check_suite_focus=true#step:4:39)Try 'grep --help' for more information.

[40](https://github.com/fmuyassarov/cluster-api-provider-metal3/runs/3802595227?check_suite_focus=true#step:4:40)+ export PREVIOUS_TAG=

[41](https://github.com/fmuyassarov/cluster-api-provider-metal3/runs/3802595227?check_suite_focus=true#step:4:41)

[42](https://github.com/fmuyassarov/cluster-api-provider-metal3/runs/3802595227?check_suite_focus=true#step:4:42)+ PREVIOUS_TAG=

[43](https://github.com/fmuyassarov/cluster-api-provider-metal3/runs/3802595227?check_suite_focus=true#step:4:43)+ echo

[44](https://github.com/fmuyassarov/cluster-api-provider-metal3/runs/3802595227?check_suite_focus=true#step:4:44)+ mkdir -p out

[45](https://github.com/fmuyassarov/cluster-api-provider-metal3/runs/3802595227?check_suite_focus=true#step:4:45)+ mkdir -p releasenotes

[46](https://github.com/fmuyassarov/cluster-api-provider-metal3/runs/3802595227?check_suite_focus=true#step:4:46)+ go run ./hack/tools/release/notes.go --from=

Thanks in advance!

I assume the problem is that by default actions/checkout retrieves only the commit (by ID) that triggered the build, not tags or branches. And without those available Git can’t find the tag you’re looking for.

The easiest solution is probably to run actions/checkout with its fetch-depth option:

      - name: checkout code
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

However that will download everything in the repository history, so if it’s a big repository you might want to target a little more narrowly, e.g. run git fetch -t after checkout or something.

Wow, this was indeed something I was missing. Thanks a lot @airtower-luna I spent almost two days on this.

1 Like