Home > OS >  How to bump version with GitHub Actions
How to bump version with GitHub Actions

Time:08-12

I want to bump the version by running my shell script. I am manually triggering the GitHub Actions with inputs. I am using GitHub API to get the latest version and I want to run my shell script with the version taken from GitHub API.

I am able to achieve everything. It's just that I am not able to get the version output.

This is my GitHub Workflow:

#############################################################################
# GitHub Action to bump release version
#
#############################################################################
name: "Bump version and Update Milestone"
on:
  workflow_dispatch:
    inputs:
      version:
        description: 'New Version'
        required: true
        default: 'warning'
permissions:
  contents: write
  pull-requests: write
jobs:
  printInputs:
      runs-on: ubuntu-latest
      steps:
        - run: |
            echo "Latest Version: ${{ github.event.inputs.version }}"
  bump:
    name: Bump version
    runs-on: ubuntu-latest
    steps:
      - name: Checkout the latest code
        uses: actions/checkout@v2
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
      - name: Get the version
        id: get_version
        run: |
         VERSION=$(curl -s https://api.github.com/repos/checkstyle/checkstyle/releases/latest \
                        | jq ".tag_name") 
         echo VERSION="$VERSION"
      - name: Modify File
        run: |
          ./.ci/bump-version.sh ${{ steps.get_version.VERSION }}
      - name: Push commit
        run: |
          git config --global user.name 'github-actions[bot]'
          git config --global user.email 'github-actions[bot]@users.noreply.github.com'
          git commit -am "minor: Bump release version to ${{ steps.get_version.VERSION }}"
          git push
      - name: GitHub Milestone
        run: |
          .ci/update-github-milestone.sh

This is my shell script:

#!/bin/bash
set -e

VERSION=$1
echo VERSION="$VERSION"

echo "bump version in pom.xml"
mvn versions:set -DnewVersion="$VERSION" && mvn versions:commit

And these is my tested actions where I want help: enter image description here

Action link: https://github.com/Rahulkhinchi03/checkstyle/runs/7785606554?check_suite_focus=true

CodePudding user response:

To transfer an output from one step to another, you need to use a workflow command:

echo "::set-output name=VERSION::$VERSION"

and then reference it like this in a later step via the outputs object:

run: |
  ./.ci/bump-version.sh ${{ steps.get_version.outputs.VERSION }}
  • Related