diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 680cf5cb..dd5d6ada 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -231,6 +231,14 @@ jobs: with: submodules: recursive + - name: Set outputs + id: vars + # Create ${{ steps.vars.outputs.sha_short }} + run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + - name: Check outputs + run: echo ${{ steps.vars.outputs.sha_short }} + # Set Up Ruby Tools - name: Set Up Ruby Tools uses: ruby/setup-ruby@v1 @@ -243,13 +251,20 @@ jobs: shell: bash run: | echo "short_ver=$(ruby ./lib/ceedling/version.rb)" >> $GITHUB_ENV - echo "full_ver=$(ruby ./lib/ceedling/version.rb)-$(git rev-parse --short HEAD)" >> $GITHUB_ENV + echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + echo "full_ver=$(ruby ./lib/ceedling/version.rb)-${{ env.sha_short }}" >> $GITHUB_ENV # Build Gem - name: Build Gem run: | gem build ceedling.gemspec + # Create Git Commit SHA file in root of checkout + - name: Git Commit SHA file + shell: bash + run: | + echo "${{ env.sha_short }}" > ./GIT_COMMIT_SHA + # Create Unofficial Release - name: Create Pre-Release uses: actions/create-release@v1 diff --git a/.gitignore b/.gitignore index 256cceb2..b3cb00bb 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ ceedling-*.gem .ruby-version /.idea /.vscode +/GIT_COMMIT_SHA diff --git a/bin/cli_handler.rb b/bin/cli_handler.rb index 236ad036..785d8fea 100644 --- a/bin/cli_handler.rb +++ b/bin/cli_handler.rb @@ -352,13 +352,16 @@ def create_example(env, app_cfg, options, name, dest) def version() require 'ceedling/version' + commit_sha = Ceedling::Version::CEEDLING_GIT_SHA + commit_sha = commit_sha.nil? ? '' : "-#{commit_sha}" + version = <<~VERSION Welcome to Ceedling! - Ceedling => #{Ceedling::Version::CEEDLING} - CMock => #{Ceedling::Version::CMOCK} - Unity => #{Ceedling::Version::UNITY} - CException => #{Ceedling::Version::CEXCEPTION} + Ceedling => #{Ceedling::Version::CEEDLING_TAG}#{commit_sha} + CMock => #{Ceedling::Version::CMOCK_TAG} + Unity => #{Ceedling::Version::UNITY_TAG} + CException => #{Ceedling::Version::CEXCEPTION_TAG} VERSION @loginator.log( version, Verbosity::NORMAL, LogLabels::TITLE ) end diff --git a/bin/cli_helper.rb b/bin/cli_helper.rb index e0f6ddfd..615d9828 100644 --- a/bin/cli_helper.rb +++ b/bin/cli_helper.rb @@ -43,7 +43,7 @@ def create_project_file(dest, local) # Clone the project file and update internal version require 'ceedling/version' @actions._copy_file( source_filepath, project_filepath, :force => true) - @actions._gsub_file( project_filepath, /:ceedling_version:\s+'\?'/, ":ceedling_version: #{Ceedling::Version::CEEDLING}" ) + @actions._gsub_file( project_filepath, /:ceedling_version:\s+'\?'/, ":ceedling_version: #{Ceedling::Version::CEEDLING_TAG}" ) end diff --git a/docs/Changelog.md b/docs/Changelog.md index 7cf5a9d1..82e35f1e 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -125,6 +125,21 @@ Ceedling logging now optionally includes emoji and nice Unicode characters. Ceed The application commands `ceedling new` and `ceedling upgrade` at the command line provide project creation and management functions. Optionally, these commands can vendor tools and libraries locally alongside your project. These vendoring options now include license files along with the source of the vendored tools and libraries. +### Git Commit Short SHA in Ceedling version + +``` +🌱 Welcome to Ceedling! + + Ceedling => #.#.#- + CMock => #.#.# + Unity => #.#.# + CException => #.#.# +``` + +If the information is unavailable such as in local development, the SHA is omitted. + +This source for this string is intended to be generated and captured in the Gem at the time of an automated build in CI. + ## 💪 Fixed ### `:paths` and `:files` handling bug fixes and clarification diff --git a/lib/ceedling/version.rb b/lib/ceedling/version.rb index ea37b206..522adaae 100644 --- a/lib/ceedling/version.rb +++ b/lib/ceedling/version.rb @@ -13,21 +13,26 @@ module Ceedling module Version - GEM = "1.0.0" - CEEDLING = GEM + GEM = '1.0.0' + CEEDLING_TAG = GEM - # If this file is loaded, we know it is next to the vendor path to use for version lookups - vendor_path = File.expand_path( File.join( File.dirname( __FILE__ ), '../../vendor' ) ) + project_root = File.join( File.dirname( __FILE__ ), '../..' ) + + # If this file (version.rb) is loaded, we know it is next to the vendor path to use for version lookups + vendor_path = File.expand_path( File.join( project_root, 'vendor' ) ) + + # Set the constant for Git SHA if it exists as simple text file in the root of the codebase + commit_sha_filepath = File.join( project_root, 'GIT_COMMIT_SHA' ) + CEEDLING_GIT_SHA = (File.exist?( commit_sha_filepath ) ? File.read( commit_sha_filepath ).strip() : nil) # Anonymous hash - { - 'UNITY' => File.join( 'unity', 'src', 'unity.h' ), - 'CMOCK' => File.join( 'cmock', 'src', 'cmock.h' ), + { 'UNITY' => File.join( 'unity', 'src', 'unity.h' ), + 'CMOCK' => File.join( 'cmock', 'src', 'cmock.h' ), 'CEXCEPTION' => File.join( 'c_exception', 'lib', 'CException.h' ) }.each_pair do |name, path| filename = File.join( vendor_path, path ) - # Actually look up the versions + # Actually look up the version number components a = [0,0,0] begin @@ -42,10 +47,10 @@ module Version end # Splat it to crete the final constant - eval("#{name} = '#{a.join(".")}'") + eval("#{name}_TAG = '#{a.join(".")}'") end # If run as a script, end with printing Ceedling’s version to $stdout - puts CEEDLING if (__FILE__ == $0) + puts CEEDLING_TAG if (__FILE__ == $0) end end