vpenades пре 1 година
родитељ
комит
5919764b04

+ 15 - 0
.github/workflows/FormatSemver.sh

@@ -0,0 +1,15 @@
+# set input or default
+
+DEFAULTPACKAGEVERSION="1.0.0-Test-DATE-TIME"
+PACKAGEVERSION=${1:-$DEFAULTPACKAGEVERSION}
+
+# replace date
+DATE_SHORT=$(date +'%Y%m%d')
+PACKAGEVERSION="${PACKAGEVERSION/DATE/$DATE_SHORT}"
+
+# replace time
+TIME_SHORT=$(date +'%H%M%S')
+PACKAGEVERSION="${PACKAGEVERSION/TIME/$TIME_SHORT}"
+
+# report semver
+echo "GHENV_PACKAGEVERSION=$PACKAGEVERSION"

+ 25 - 3
.github/workflows/PublishToGithub.yml

@@ -4,12 +4,25 @@ on: workflow_dispatch
     
 jobs:
 
-  build_job:
+  prepare_job: #---------------------------------------------------------------------------------------
+    runs-on: ubuntu-latest
+    
+    steps:
+    - name: Define Version at GHENV_PACKAGEVERSION
+      run: |
+        chmod +x ./.github/workflows/FormatSemver.sh
+        ./.github/workflows/FormatSemver.sh "${{ vars.SharpGLTF_Version }}-Preview-DATE-TIME" >> $GITHUB_ENV
+
+    outputs:
+      semver: "${{env.GHENV_PACKAGEVERSION}}" 
+
+  build_job: #---------------------------------------------------------------------------------------
+    needs: prepare_job
     uses: ./.github/workflows/BuildPackages.yml
     with:
-      nuget-semver: ${{ vars.SharpGLTF_Version }}-Preview-DATE-TIME
+      nuget-semver: "${{needs.prepare_job.outputs.semver}}"
 
-  publish_job:
+  publish_job: #---------------------------------------------------------------------------------------
     needs: build_job
     runs-on: ubuntu-latest
 
@@ -22,3 +35,12 @@ jobs:
 
     - name: Push to NuGet
       run: dotnet nuget push "*.nupkg" --api-key ${{secrets.SharpGLTF_PublishToGithub}} --source https://nuget.pkg.github.com/${{github.repository_owner}}
+
+  tag_job: #---------------------------------------------------------------------------------------
+    needs: [ prepare_job, build_job ]
+    permissions:
+      contents: write # required for pushing the tag    
+    uses: ./.github/workflows/PushGithubTag.yml
+    with:
+      tag-name: "${{needs.prepare_job.outputs.semver}}"
+      message: "Tag for ${{needs.prepare_job.outputs.semver}}"

+ 59 - 0
.github/workflows/PushGithubTag.yml

@@ -0,0 +1,59 @@
+name: Push a new github tag
+
+on:
+
+  workflow_dispatch:
+    inputs:
+      tag-name:
+        type: string
+        description: 'name of the tag'
+        required: true
+        default: 'tag'
+      message:
+        type: string
+        description: 'message'
+        required: false
+        default: 'message'
+
+  workflow_call:
+    inputs:
+      tag-name:
+        type: string
+        description: 'name of the tag'
+        required: true
+        default: 'tag'
+      message:
+        type: string
+        description: 'message'
+        required: false
+        default: 'message'
+    
+jobs:
+  build_job:
+
+    runs-on: ubuntu-latest    
+    timeout-minutes: 1
+    permissions:
+      contents: write # required for pushing the tag
+
+    steps:    
+
+    - name: Checkout
+      uses: actions/checkout@v4
+
+    # https://github.com/orgs/community/discussions/40405
+    - run: |
+        git config --global user.name "${{ github.actor }}"
+        git config --global user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com"
+        git tag -a "${{inputs.tag-name}}" -m "${{inputs.message}}"
+        git push origin "${{inputs.tag-name}}"
+
+    # # alternative solution:
+    # # https://github.com/rickstaa/action-create-tag
+    # - name: create tag
+    #   uses: rickstaa/action-create-tag@v1
+    #   id: "tag_create"
+    #   with:
+    #     tag: "${{inputs.tag-name}}"
+    #     tag_exists_error: true
+    #     message: "${{inputs.message}}"

+ 1 - 0
SharpGLTF.sln

@@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
 		.github\workflows\IncrementVersion.yml = .github\workflows\IncrementVersion.yml
 		.github\workflows\PublishToGithub.yml = .github\workflows\PublishToGithub.yml
 		.github\workflows\PublishToNuget.yml = .github\workflows\PublishToNuget.yml
+		.github\workflows\PushGithubTag.yml = .github\workflows\PushGithubTag.yml
 		README.md = README.md
 		SharpGLTF.Build.sh = SharpGLTF.Build.sh
 		SharpGLTF.ruleset = SharpGLTF.ruleset