diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml new file mode 100644 index 0000000..fbbe4c1 --- /dev/null +++ b/.github/workflows/cicd.yml @@ -0,0 +1,84 @@ +# 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: CICD + +on: + push: + branches: [ "main" ] + +jobs: + generate-version: + runs-on: ubuntu-latest + + permissions: # to publish the new tag to github + contents: write + + steps: + - uses: actions/checkout@v4 + - name: Github Tag Bump + id: tag_bump + uses: anothrNick/github-tag-action@1.67.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + INITIAL_VERSION: 1.0.2 # this comes from your Contracts pkg + DEFAULT_BUMP: patch # 1.0.x + + outputs: + new_version: ${{ steps.tag_bump.outputs.new_tag }} # store the generated tag + + + package-and-publish-contracts: + + runs-on: ubuntu-latest + needs: generate-version + + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v4 + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 7.0.x + source-url: https://nuget.pkg.github.com/${{github.repository_owner}}/index.json + env: + NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Pack + run: | + dotnet pack src/Play.Catalog.Contracts/ \ + --configuration Release \ + -p:PackageVersion=${{ needs.generate-version.outputs.new_version }} \ + -p:RepositoryUrl=https://github.com/${{github.repository_owner}}/play.catalog \ + -o packages + + - name: Publish + run: dotnet nuget push packages/*.nupkg + + # build docker image + build-and-deploy-service: + + runs-on: ubuntu-latest + needs: generate-version + + env: + APP_NAME: play-economy-microservices + + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v4 # checkout the latest code + + - name: Build and push Docker images + uses: docker/build-push-action@v6.9.0 + with: + # List of secrets to expose to the build (e.g., key=string, GIT_AUTH_TOKEN=mytoken) + secrets: | + "GH_OWNER=${{github.repository_owner}}" + "GH_PAT=${{secrets.GH_PAT}}" + tags: ${{env.APP_NAME}}.azurecr.io/play.catalog:${{ needs.generate-version.outputs.new_version }}