Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give Github Action the content of a file as input?

I have a workflow with an action that creates a version number when building an artefact. This version number is written to file.

How can I give that as an input to another action?

I.e: How can I use this version number as part of a commit message in another action?

like image 759
jactor-rises Avatar asked Nov 22 '25 01:11

jactor-rises


1 Answers

Per the fabulous answer here, there's actually an inline way to accomplish this. Not intuitive at all, except that the ::set-output... syntax matches the same expected output format for GitHub Actions.

The below step loads the VERSION file into ${{ steps.getversion.outputs.version }}:

      - name: Read VERSION file
        id: getversion
        run: echo "::set-output name=version::$(cat VERSION)"

I had the same use case as OP, so I'm pasting below my entire code, which does three things:

  1. Pull first three-parts of the 4-part version string from the file VERSION.
  2. Get a sequential build number using the einaregilsson/build-number@v2 action.
  3. Concatenate these two into an always-unique 4-part version string that becomes a new GitHub release.
name: Auto-Tag Release

on:
  push:
    branches:
      - master

jobs:
  release_new_tag:
    runs-on: ubuntu-latest
    steps:
      - name: "Checkout source code"
        uses: "actions/checkout@v1"
      - name: Generate build number
        id: buildnumber
        uses: einaregilsson/build-number@v2
        with:
          token: ${{secrets.github_token}}
      - name: Read VERSION file
        id: getversion
        run: echo "::set-output name=version::$(cat VERSION)"
      - uses: "marvinpinto/action-automatic-releases@latest"
        with:
          repo_token: "${{ secrets.GITHUB_TOKEN }}"
          automatic_release_tag: v${{ steps.getversion.outputs.version }}.${{ steps.buildnumber.outputs.build_number }}
          prerelease: false

Fully automated release management! :-)

  • Note: The branch filter at top ensures that we only run this on commits to master.
like image 188
aaronsteers Avatar answered Nov 24 '25 04:11

aaronsteers