From 729c708223fd9240e1893ec8405b449fb642c69e Mon Sep 17 00:00:00 2001 From: manuel-fernandez-rodriguez <48520205+manuel-fernandez-rodriguez@users.noreply.github.com> Date: Fri, 13 Dec 2024 03:52:35 +0100 Subject: [PATCH] Added new build and publish workflows (#22) --- .github/workflows/registerly-build.yml | 53 +++++++++++++++++++++--- .github/workflows/registerly-publish.yml | 25 +++++++++++ 2 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/registerly-publish.yml diff --git a/.github/workflows/registerly-build.yml b/.github/workflows/registerly-build.yml index cd33eb0..13c8f8e 100644 --- a/.github/workflows/registerly-build.yml +++ b/.github/workflows/registerly-build.yml @@ -1,7 +1,5 @@ -# This workflow will build a .NET project -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net - name: Build Registerly +concurrency: Registerly on: push: @@ -12,21 +10,66 @@ on: paths: [ "Registerly/**" ] workflow_dispatch: +env: + PROJECT: Registerly + jobs: build: runs-on: ubuntu-latest + + permissions: + contents: write steps: - uses: actions/checkout@v4 + - name: Get version + if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch'}} + id: get-version + uses: kzrnm/get-net-sdk-project-versions-action@v2 + with: + proj-path: ./${{ env.PROJECT }}/src/DeviantCoding.${{ env.PROJECT }}.csproj + - name: Check version is valid + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ env.PROJECT }}-${{ steps.get-version.outputs.version }} + title: ${{ env.PROJECT }} v${{ steps.get-version.outputs.version }} + prerelease: ${{ steps.get-version.outputs.version-suffix != '' && '--prerelease' || '' }} + run: | + PUBLISHED_RELEASE_NAME="$(gh release list --json name,tagName,isDraft --jq '.[] | select(.tagName=="${{ env.tag }}" and .isDraft==false)|.name')" + if [ -n "${PUBLISHED_RELEASE_NAME}" ] + then + echo "Error! There is already a published release with version ${{ env.tag }}" + exit 1 + fi + shell: bash - name: Setup .NET uses: actions/setup-dotnet@v4 with: dotnet-version: 8.0.x - name: Build run: | - chmod +x ./Registerly/build.sh - cd ./Registerly/ + chmod +x ./${{ env.PROJECT }}/build.sh + cd ./${{ env.PROJECT }}/ ./build.sh + shell: bash + - name: Create or update release + if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch'}} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + tag: ${{ env.PROJECT }}-${{ steps.get-version.outputs.version }} + title: ${{ env.PROJECT }} v${{ steps.get-version.outputs.version }} + prerelease: ${{ steps.get-version.outputs.version-suffix != '' && '--prerelease' || '' }} + run: | + DRAFT_RELEASE_NAME="$(gh release list --json name,tagName,isDraft --jq '.[] | select(.tagName=="${{ env.tag }}" and .isDraft)|.name')" + if [ -z "${DRAFT_RELEASE_NAME}" ] + then + gh release create "$tag" ./${{ env.PROJECT }}/src/bin/Release/*.nupkg --draft ${prerelease:+"$prerelease"} --title "$title" --target ${{ github.sha }} + else + echo "Updating existing release $tag" + gh release upload "$tag" ./${{ env.PROJECT }}/src/bin/Release/*.nupkg --clobber + gh release edit "$tag" --target ${{ github.sha }} + fi shell: bash + diff --git a/.github/workflows/registerly-publish.yml b/.github/workflows/registerly-publish.yml new file mode 100644 index 0000000..9dbbab8 --- /dev/null +++ b/.github/workflows/registerly-publish.yml @@ -0,0 +1,25 @@ +name: Publish Registerly +concurrency: Registerly + +on: + release: + types: [published] + +env: + PROJECT: Registerly + +jobs: + deployment: + runs-on: ubuntu-latest + environment: NUGETTEST.ORG + steps: + - name: Get package + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_REPO: ${{ github.repository_owner }}/${{ github.event.repository.name }} + tag: ${{ github.ref_name }} + run: | + gh release download "${{ env.tag }}" + shell: bash + - name: Publish to nuget.org + run: dotnet nuget push ./*.nupkg --api-key ${{ secrets.NUGETORG_APIKEY }} --source ${{ vars.NUGETORG_URL }}