Skip to content

Commit

Permalink
Replace GitVersion with get-version.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
desplesda committed Mar 9, 2025
1 parent c6ca11d commit 4c0b472
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 21 deletions.
31 changes: 11 additions & 20 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ on:
jobs:
# This workflow contains a single job called "build"
build:
env:
RELEASE_FLAG: false
LANGUAGESERVER_REF: "000000"

# The type of runner that the job will run on
runs-on: ubuntu-latest

Expand Down Expand Up @@ -60,29 +64,16 @@ jobs:
- name: Run unit tests
run: npm test

- name: Install GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: "6.x"

- name: Execute GitVersion
id: gitversion # step id used as reference for output values
uses: gittools/actions/gitversion/[email protected]

- name: Print version information
run: |
echo "Major: ${{ steps.gitversion.outputs.major }}"
echo "Minor: ${{ steps.gitversion.outputs.minor }}"
echo "Patch: ${{ steps.gitversion.outputs.patch }}"
echo "MajorMinorPatch: ${{ steps.gitversion.outputs.majorMinorPatch }}"
echo "SemVer: ${{ steps.gitversion.outputs.semVer }}"
- name: Get version
id: version
run: ./get-version.sh

- name: Update metadata in package.json
uses: onlyutkarsh/[email protected]
with:
files: "${{github.workspace}}/package.json"
patch-syntax: |
= /version => "${{ steps.gitversion.outputs.majorMinorPatch }}"
= /version => "${{ steps.version.outputs.MajorMinorCommits }}"
# If is a push, and the commit message does not contain the string
# '[release]', build as pre-release. (This is used in the final step.)
Expand All @@ -99,13 +90,13 @@ jobs:
- name: Upload .vsix as artifact
uses: actions/upload-artifact@v4
with:
name: yarn-spinner-${{steps.gitversion.outputs.majorMinorPatch}}.vsix
path: ${{github.workspace}}/yarn-spinner-${{steps.gitversion.outputs.majorMinorPatch}}.vsix
name: yarn-spinner-${{steps.version.outputs.MajorMinorCommits}}.vsix
path: ${{github.workspace}}/yarn-spinner-${{steps.version.outputs.MajorMinorCommits}}.vsix

# If this is a push to the main branch, publish to the Marketplace using our configuration.
- name: Publish to Marketplace
if: success() && github.ref == 'refs/heads/main' && github.event_name == 'push'
env:
VSCE_PAT: ${{ secrets.VSCE_PAT }}
run: |
npx vsce publish ${{ env.RELEASE_FLAG }} -i ${{github.workspace}}/yarn-spinner-${{steps.gitversion.outputs.majorMinorPatch}}.vsix
npx vsce publish ${{ env.RELEASE_FLAG }} -i ${{github.workspace}}/yarn-spinner-${{steps.version.outputs.MajorMinorCommits}}.vsix
Empty file removed GitVersion.yml
Empty file.
57 changes: 57 additions & 0 deletions get-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

# Get info about the current commit
most_recent_tag=$(git describe --tags --match="v*" --abbrev=0)
commits_since_tag=$(git rev-list $most_recent_tag..HEAD | wc -l | awk '{$1=$1};1')
sha=$(git log -1 --format=%H)
short_sha=$(git log -1 --format=%h)
branch=$(git rev-parse --abbrev-ref HEAD)

total_commit_count=$(git rev-list HEAD | wc -l | awk '{$1=$1};1')

# A regex for extracting data from a version number: major, minor, patch,
# [prerelease]
REGEX='v(\d+)\.(\d+)\.(\d+)(-.*)?'

raw_version=${1:-"$most_recent_tag"}

# Extract the data from the version number
major=$(echo $raw_version | perl -pe "s|$REGEX|\1|" )
minor=$(echo $raw_version | perl -pe "s|$REGEX|\2|" )
patch=$(echo $raw_version | perl -pe "s|$REGEX|\3|" )
prerelease=$(echo $raw_version | perl -pe "s|$REGEX|\4|" )

# Calculate the semver from the version (should be the same as the version, but
# just in case)
SemVer="$major.$minor.$patch$prerelease"

MajorMinorCommits="$major.$minor.$total_commit_count"

# If there are any commits since the current tag and we aren't overriding our
# version, add that note
if [ "$commits_since_tag" -gt 0 -a -z "$1" ]; then
SemVer="$SemVer+$commits_since_tag"
fi

# Create the version strings we'll write into the AssemblyInfo files
OutputAssemblyVersion=$(echo "$major.$minor.$patch.$commits_since_tag" | perl -pe "s|\/|\\\/|" )
OutputAssemblyInformationalVersion=$(echo "$SemVer.Branch.$branch.Sha.$sha" | perl -pe "s|\/|\\\/|" )
OutputAssemblyFileVersion=$(echo "$major.$minor.$patch.$commits_since_tag" | perl -pe "s|\/|\\\/|" )

# Update the AssemblyInfo.cs files
for infoFile in $(find . -name "AssemblyInfo.cs"); do
perl -pi -e "s/AssemblyVersion\(\".*\"\)/AssemblyVersion(\"$OutputAssemblyVersion\")/" $infoFile
perl -pi -e "s/AssemblyInformationalVersion\(\".*\"\)/AssemblyInformationalVersion(\"$OutputAssemblyInformationalVersion\")/" $infoFile
perl -pi -e "s/AssemblyFileVersion\(\".*\"\)/AssemblyFileVersion(\"$OutputAssemblyFileVersion\")/" $infoFile
done

# If we're running in GitHub Workflows, output our calculated SemVer
if [[ -n $GITHUB_OUTPUT ]]; then
echo "SemVer=$SemVer" >> "$GITHUB_OUTPUT"
echo "ShortSha=$short_sha" >> "$GITHUB_OUTPUT"
echo "MajorMinorCommits=$MajorMinorCommits" >> "$GITHUB_OUTPUT"
fi

# Log our SemVer
echo $SemVer
echo $MajorMinorCommits
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "yarn-spinner",
"displayName": "Yarn Spinner",
"description": "Adds support for the Yarn Spinner dialogue language.",
"version": "3.0.0-beta1",
"version": "3.0.0",
"homepage": "https://yarnspinner.dev",
"repository": "https://github.com/YarnSpinnerTool/VSCodeExtension",
"license": "MIT",
Expand Down

0 comments on commit 4c0b472

Please sign in to comment.