Browse Source

actions++

vpenades 1 year ago
parent
commit
ee14da4aa3

+ 15 - 0
.github/actions/Build/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"

+ 31 - 0
.github/actions/Build/action.yml

@@ -0,0 +1,31 @@
+name: 'Build packages and store artifacts'
+description: 'Build packages and store artifacts'
+
+inputs:
+  nuget-semver:  
+    description: 'package version'
+    required: false
+    default: '1.0.0-Test-DATE-TIME'
+    
+runs:
+  using: 'composite'  
+
+  steps:        
+
+    - name: Setup .NET SDK
+      uses: actions/setup-dotnet@v4
+
+    - name: Build
+      run: |
+        chmod +x ./SharpGLTF.Build.sh
+        ./SharpGLTF.Build.sh ${{inputs.nuget-semver}}
+      shell: bash      
+
+    - name: Archive
+      uses: actions/upload-artifact@v4
+      with:
+        name: nuget-packages
+        retention-days: 1
+        path: |
+            *.nupkg
+            *.snupkg

+ 38 - 0
.github/actions/PushGithubTag/action.yml

@@ -0,0 +1,38 @@
+name: 'Push Github Tag'
+description: 'Pushes a new github tag from Master'
+
+inputs:
+  tag-name:    
+    description: 'name of the tag'
+    required: true
+    default: 'tag'
+  message:    
+    description: 'message'
+    required: false
+    default: 'message'      
+
+runs:
+  using: 'composite'  
+
+  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}}"
+    shell: bash
+
+  # # 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}}"

+ 5 - 8
.github/workflows/PublishToGithub.yml

@@ -40,11 +40,8 @@ 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}}"
+    - name: create tag
+      uses: ./.github/actions/PushGithubTag
+      with:
+        tag-name: "${{env.GHENV_PACKAGEVERSION}}"
+        message: "new tag for ${{env.GHENV_PACKAGEVERSION}}"

+ 26 - 3
.github/workflows/PublishToNuget.yml

@@ -4,12 +4,29 @@ on: workflow_dispatch
     
 jobs:
 
-  build_job:
+  prepare_job: #---------------------------------------------------------------------------------------
+    runs-on: ubuntu-latest
+    
+    steps:
+
+    - name: Checkout
+      uses: actions/checkout@v4
+
+    - name: Define Version at GHENV_PACKAGEVERSION
+      run: |
+        chmod +x ./.github/workflows/FormatSemver.sh
+        ./.github/workflows/FormatSemver.sh "${{ vars.SharpGLTF_Version }}-Alpha${{ vars.SharpGLTF_AlphaVersion }}" >> $GITHUB_ENV
+
+    outputs:
+      semver: "${{env.GHENV_PACKAGEVERSION}}" 
+
+  build_job: #---------------------------------------------------------------------------------------
+    needs: prepare_job
     uses: ./.github/workflows/BuildPackages.yml
     with:
-      nuget-semver: ${{ vars.SharpGLTF_Version }}-alpha${{ vars.SharpGLTF_AlphaVersion }}
+      nuget-semver: "${{needs.prepare_job.outputs.semver}}"
 
-  publish_job:
+  publish_job: #---------------------------------------------------------------------------------------
     needs: build_job
     runs-on: ubuntu-latest
 
@@ -22,3 +39,9 @@ jobs:
 
     - name: Push to NuGet
       run: dotnet nuget push "*.nupkg" --api-key ${{secrets.SharpGLTF_PublishToNuget}} --source https://api.nuget.org/v3/index.json
+
+    - name: create tag
+      uses: ./.github/actions/PushGithubTag
+      with:
+        tag-name: "${{env.GHENV_PACKAGEVERSION}}"
+        message: "new tag for ${{env.GHENV_PACKAGEVERSION}}"