The-Standard-Organization / ADotNet

ADotNet is a.NET library that enables software engineers on the .NET platform to develop AzureDevOps pipelines and Git Actions in C#.
98 stars 34 forks source link

RELEASES: Add Git Tag Job #59

Closed glhays closed 1 year ago

glhays commented 1 year ago

Closes: #58

AddTagJob

glhays commented 1 year ago

Can you run the infrastructure build project and check in the newly generated dotnet.yaml

Infrastructure.Build run results....

Screenshot 2023-05-12 164332

glhays commented 1 year ago

Can you add some screenshots to show the tags were added as expected?

Only added in the the Test.Console

cjdutoit commented 1 year ago

@glhays here is a working version of my POC. I could not get a combined version of tagging as well as the other jobs to work together in a single yaml file as you need types: closed for the merge event. In the same file that job was always skipped.

on:
  pull_request:
    types:
      - closed

I created a seperate yaml file just for tagging and it seems to do the job. It pulls the version from the proj file and use the version to create a tag Release-1.0.0

Also, I could not add a tag without authenticating. I had to create a Personal Access Token. I did not want to hardcode my name on the user.name OR user.email, but adding the fake details like this still works with the access token.

Here is my current version of the tagging
```yaml
name: Add Git Release Tag on Merge to Main
on:
  pull_request:
    types:
      - closed
    branches:
      - main

jobs:
  add_release_tag:
    if: github.event.pull_request.merged && github.event.pull_request.base.ref == 'main' && startsWith(github.event.pull_request.title, 'RELEASES:') && (contains(github.event.pull_request.labels.*.name, 'RELEASE') || contains(github.event.pull_request.labels.*.name, 'RELEASE'))  

    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Extract Version Number
        id: extract_version
        run: echo "::set-output name=version_number::$(grep -oP '(?<=<Version>)[^<]+' BuildTestApp/BuildTestApp.csproj)"

      - name: Print Version Number
        run: echo "Version number is ${{ steps.extract_version.outputs.version_number }}"

      - name: Configure Git
        run: |
          git config user.name "Add Git Release Tag Action"
          git config user.email "github.action@noreply.github.com"

      - name: Authenticate with GitHub
        uses: actions/checkout@v2
        with:
          token: ${{ secrets.PAT_FOR_TAGGING }}

      - name: Add Git Tag - Release
        run: |
          git tag -a "release-${{ steps.extract_version.outputs.version_number }}" -m "Release ${{ steps.extract_version.outputs.version_number }}"
          git push origin --tags
cjdutoit commented 1 year ago

Can you run the infrastructure build project and check in the newly generated dotnet.yaml

Infrastructure.Build run results....

Screenshot 2023-05-12 164332

55 will add the tag for the push filter.

on:
  push:
    tags:
    - RELEASE

This issue is only to Add A Tag, not the filters.

cjdutoit commented 1 year ago

Can you add some screenshots to show the tags were added as expected?

Only added in the the Test.Console

You will need to provide more evidence. Take the generated yaml and add it to a private repo to test the outcomes. i.e. the below one showed the add_tag was skipped as we dont do it on a PR. image

but on this one, you can see that the tagging happened on main.

image image

glhays commented 1 year ago

I think it best I revert my code and close the pr, as the ASk for this issue has changed. Understandably so due to your testing result(s). Any thoughts?

cjdutoit commented 1 year ago

I think it best I revert my code and close the pr, as the ASk for this issue has changed. Understandably so due to your testing result(s). Any thoughts?

Thanks. I think if you can do just the Nuget Deploy as a working POC as per #50, then we can just add the if: condition to that step one this is done.

It would probably not take that long now to finish off #58 from what we have done on the POC.