From e7e6385ddd9f14307c597e4fbbd6ef217aac44fa Mon Sep 17 00:00:00 2001 From: dangershony Date: Mon, 22 Jul 2024 16:00:11 +0100 Subject: [PATCH] Push a workflow that will trigger on version file change --- .github/workflows/build.yml | 62 +++------- .github/workflows/docker-release.yml | 39 ++++++ .../workflows/{deploy.yml => gh-deploy.yml} | 0 .github/workflows/release.yml | 115 ++++++++++++++---- 4 files changed, 148 insertions(+), 68 deletions(-) create mode 100644 .github/workflows/docker-release.yml rename .github/workflows/{deploy.yml => gh-deploy.yml} (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a44d18d2..15f49464 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,16 +2,12 @@ name: Build and create a Release on: push: - # branches: - # - main - tags: - - 'v*.*.*' + branches: + - main workflow_dispatch: jobs: build: - # if the presence of '-release' exists in the tag abort - if: startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, '-release') strategy: matrix: os: [windows-latest, ubuntu-latest, macos-latest] @@ -64,43 +60,23 @@ jobs: - name: Unit Test run: dotnet test -v=normal -c ${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_PATH}} - - name: Publish (Angor) - run: dotnet publish -c ${{env.BUILD_CONFIGURATION}} -r ${{matrix.runtime}} /p:Version=${{ env.VERSION }} -v m -o ./src/${{ env.PROJECT_NAME }}/bin/publish ${{env.PROJECT_PATH}} - - - name: Package Name + - name: Check for changes in Directory.Build.props + id: check_changes run: | - echo RELEASE_NAME=${{ env.PROJECT_NAME }}-${{ env.VERSION }}-${{ matrix.runtime }}${{ matrix.extension }} >> $GITHUB_ENV - echo RELEASE_PATH=${{ env.PROJECT_NAME }}-${{ env.VERSION }}-${{ matrix.runtime }}${{ matrix.extension }} >> $GITHUB_ENV - shell: bash + if git diff --name-only HEAD^ HEAD | grep -q '^Directory.Build.props$'; then + echo "File Directory.Build.props has changed." + echo "::set-output name=changed::true" + else + echo "File Directory.Build.props has not changed." + echo "::set-output name=changed::false" + fi - - name: Package (Linux) - if: matrix.os == 'ubuntu-latest' - run: | - echo RELEASE_PATH=./src/${{env.PROJECT_NAME}}/bin/publish/${{env.RELEASE_NAME}} >> $GITHUB_ENV - cd ./src/${{env.PROJECT_NAME}}/bin/publish/ - tar cvzf ${{env.RELEASE_NAME}} * - - name: Package (Windows) - if: matrix.os == 'windows-latest' - run: | - Compress-Archive -Path .\src\${{env.PROJECT_NAME}}\bin\publish\* -DestinationPath .\${{env.RELEASE_NAME}} - - name: Package (Mac) - if: matrix.os == 'macos-latest' + - name: Create tag + if: steps.check_changes.outputs.changed == 'true' + env: + TAG_NAME: "v${{env.VERSION}}" run: | - zip -r ${{env.RELEASE_NAME}} ./src/${{env.PROJECT_NAME}}/bin/publish/ - - - uses: actions/upload-artifact@v1 - with: - name: api - path: "${{env.RELEASE_PATH}}" - - - name: Release - uses: sondreb/action-release@main - with: - commit: "main" - token: ${{ secrets.GITHUB_TOKEN }} - files: "${{env.RELEASE_PATH}}" - draft: true - prerelease: false - body: "" - name: "Angor (Release ${{env.VERSION}})" - tag: "v${{env.VERSION}}-release" \ No newline at end of file + #git config --global user.name "${{ github.actor }}" + #git config --global user.email "${{ github.actor }}@users.noreply.github.com" + git tag $TAG_NAME + git push origin $TAG_NAME \ No newline at end of file diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml new file mode 100644 index 00000000..71a1aacd --- /dev/null +++ b/.github/workflows/docker-release.yml @@ -0,0 +1,39 @@ +name: Build and Release Docker Image +on: + release: + types: [published, prereleased] + +jobs: + build: + name: Build and Push + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + + - name: Setup dotnet + uses: actions/setup-dotnet@v1 + with: + dotnet-version: | + 8.0.x + - name: Log Variables + run: | + echo "action - ${{ github.event.action }}" + echo "url - ${{ github.event.release.url }}" + echo "assets_url - ${{ github.event.release.assets_url }}" + echo "id - ${{ github.event.release.id }}" + echo "tag_name - ${{ github.event.release.tag_name }}" + echo "assets - ${{ github.event.assets }}" + echo "assets[0] - ${{ github.event.assets[0] }}" + - uses: cschleiden/replace-tokens@v1 + with: + files: '["**/Dockerfile.Release"]' + env: + VERSION: ${{ github.event.release.tag_name }} + + - name: Build the Docker container image + run: docker build -f "./src/Angor/Server/Dockerfile.Release" -t blockcore/angor:latest -t blockcore/angor:${{ github.event.release.tag_name }} --label "unstable=true" "." + + - name: Login and Push to Docker Registry + run: | + docker login -u "sondreb" -p "${{secrets.DOCKER_KEY}}" + docker push --all-tags blockcore/angor \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/gh-deploy.yml similarity index 100% rename from .github/workflows/deploy.yml rename to .github/workflows/gh-deploy.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 71a1aacd..14445536 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,39 +1,104 @@ -name: Build and Release Docker Image +name: Build and create a Release + on: - release: - types: [published, prereleased] + push: + tags: + - 'v*.*.*' + workflow_dispatch: jobs: build: - name: Build and Push - runs-on: ubuntu-latest + # if the presence of '-release' exists in the tag abort + if: startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, '-release') + strategy: + matrix: + os: [windows-latest, ubuntu-latest, macos-latest] + include: + - os: windows-latest + extension: ".zip" + runtime: "win-x64" + - os: ubuntu-latest + extension: ".tar.gz" + runtime: "linux-x64" + - os: macos-latest + runtime: "osx-x64" + extension: ".zip" + node_version: [18] + fail-fast: false + + runs-on: ${{ matrix.os }} + + env: + PROJECT_NAME: "Angor" + SOLUTION_PATH: "src/Angor.sln" + PROJECT_PATH: "src/Angor/Server/Angor.Server.csproj" + BUILD_CONFIGURATION: "Release" + steps: - - uses: actions/checkout@master + - uses: actions/checkout@v1 + name: Checkout - name: Setup dotnet uses: actions/setup-dotnet@v1 with: - dotnet-version: | + dotnet-version: | 8.0.x - - name: Log Variables - run: | - echo "action - ${{ github.event.action }}" - echo "url - ${{ github.event.release.url }}" - echo "assets_url - ${{ github.event.release.assets_url }}" - echo "id - ${{ github.event.release.id }}" - echo "tag_name - ${{ github.event.release.tag_name }}" - echo "assets - ${{ github.event.assets }}" - echo "assets[0] - ${{ github.event.assets[0] }}" - - uses: cschleiden/replace-tokens@v1 + - name: Setup Node.js (${{ matrix.node_version }}) + uses: actions/setup-node@v1 with: - files: '["**/Dockerfile.Release"]' - env: - VERSION: ${{ github.event.release.tag_name }} + node-version: ${{ matrix.node_version }} + + - name: Variables + run: | + echo VERSION=$(npm run version --silent) >> $GITHUB_ENV + shell: bash + + - name: Workload + run: dotnet workload restore ${{env.SOLUTION_PATH}} + + - name: Restore + run: dotnet restore ${{env.SOLUTION_PATH}} - - name: Build the Docker container image - run: docker build -f "./src/Angor/Server/Dockerfile.Release" -t blockcore/angor:latest -t blockcore/angor:${{ github.event.release.tag_name }} --label "unstable=true" "." + - name: Unit Test + run: dotnet test -v=normal -c ${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_PATH}} - - name: Login and Push to Docker Registry + - name: Publish (Angor) + run: dotnet publish -c ${{env.BUILD_CONFIGURATION}} -r ${{matrix.runtime}} /p:Version=${{ env.VERSION }} -v m -o ./src/${{ env.PROJECT_NAME }}/bin/publish ${{env.PROJECT_PATH}} + + - name: Package Name + run: | + echo RELEASE_NAME=${{ env.PROJECT_NAME }}-${{ env.VERSION }}-${{ matrix.runtime }}${{ matrix.extension }} >> $GITHUB_ENV + echo RELEASE_PATH=${{ env.PROJECT_NAME }}-${{ env.VERSION }}-${{ matrix.runtime }}${{ matrix.extension }} >> $GITHUB_ENV + shell: bash + + - name: Package (Linux) + if: matrix.os == 'ubuntu-latest' + run: | + echo RELEASE_PATH=./src/${{env.PROJECT_NAME}}/bin/publish/${{env.RELEASE_NAME}} >> $GITHUB_ENV + cd ./src/${{env.PROJECT_NAME}}/bin/publish/ + tar cvzf ${{env.RELEASE_NAME}} * + - name: Package (Windows) + if: matrix.os == 'windows-latest' + run: | + Compress-Archive -Path .\src\${{env.PROJECT_NAME}}\bin\publish\* -DestinationPath .\${{env.RELEASE_NAME}} + - name: Package (Mac) + if: matrix.os == 'macos-latest' run: | - docker login -u "sondreb" -p "${{secrets.DOCKER_KEY}}" - docker push --all-tags blockcore/angor \ No newline at end of file + zip -r ${{env.RELEASE_NAME}} ./src/${{env.PROJECT_NAME}}/bin/publish/ + + - uses: actions/upload-artifact@v1 + with: + name: api + path: "${{env.RELEASE_PATH}}" + + - name: Release + uses: sondreb/action-release@main + with: + commit: "main" + token: ${{ secrets.GITHUB_TOKEN }} + files: "${{env.RELEASE_PATH}}" + draft: true + prerelease: false + body: "" + name: "Angor (Release ${{env.VERSION}})" + tag: "v${{env.VERSION}}-release" \ No newline at end of file