Skip to content

Commit

Permalink
✨ Added Git commit SHA (short) to version handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mkarlesky committed Aug 3, 2024
1 parent 61529ae commit f161395
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 16 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ ceedling-*.gem
.ruby-version
/.idea
/.vscode
/GIT_COMMIT_SHA
11 changes: 7 additions & 4 deletions bin/cli_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bin/cli_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
15 changes: 15 additions & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 => #.#.#-<Short SHA>
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
Expand Down
25 changes: 15 additions & 10 deletions lib/ceedling/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit f161395

Please sign in to comment.