Skip to content

GitHubActionsBuilds #298

GitHubActionsBuilds

GitHubActionsBuilds #298

name: GitHubActionsBuilds
on:
push:
workflow_run:
workflows: ["PR Builds"] # must match the `name:` field in pr-fork-build.yml
types:
- completed # fire when that workflow finishes
jobs:
generate_version_number:
if: github.event_name == 'push' || github.event.workflow_run.conclusion == 'success'
permissions:
contents: write
runs-on: ubuntu-latest
outputs:
build_number: ${{ steps.buildnumber.outputs.build_number }}
steps:
- name: Generate build number
id: buildnumber
uses: onyxmueller/build-tag-number@v1
with:
token: ${{secrets.github_token}}
build_docker:
needs: generate_version_number
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: devedse
password: ${{ secrets.DOCKERHUBTOKEN }}
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v3
with:
image: tonistiigi/binfmt:latest
platforms: all
- name: Available platforms
run: echo ${{ steps.qemu.outputs.platforms }}
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Builder instance name
run: echo ${{ steps.buildx.outputs.name }}
- name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
- name: Set Image Tags
id: tags
run: |
VERSION=1.0.${{needs.generate_version_number.outputs.build_number}}
echo Version: $VERSION
echo github.event_name: ${{ github.event_name }}
echo github.ref: ${{ github.ref }}
echo github.actor: ${{ github.actor }}
echo branch name: ${GITHUB_REF#refs/heads/}
BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//-/g')
echo parsed branch name: ${BRANCH_NAME}
TAGS=""
if [[ "${{ github.event_name }}" == 'workflow_run' ]]; then
PR_USERNAME=$(echo "${{ github.event.workflow_run.head_repository.owner.login }}" | tr '[:upper:]' '[:lower:]')
PR_BRANCH=$(echo "${{ github.event.workflow_run.head_branch }}" | sed 's/\//-/g')
echo "PR_USERNAME: $PR_USERNAME"
echo "PR_BRANCH: $PR_BRANCH"
TAGS="-t devedse/develancacheui_backend:pr_${PR_USERNAME}_${PR_BRANCH}"
elif [[ "${{ github.ref }}" == 'refs/heads/master' ]]; then
TAGS="-t devedse/develancacheui_backend:${VERSION} -t devedse/develancacheui_backend:latest -t devedse/develancacheui_backend:beta_nightly"
elif [[ "${{ github.actor }}" == 'dependabot[bot]' ]]; then
TAGS="-t devedse/develancacheui_backend:beta_${BRANCH_NAME}"
else
TAGS="-t devedse/develancacheui_backend:beta_${BRANCH_NAME} -t devedse/develancacheui_backend:beta_nightly"
fi
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
echo "TAGS=${TAGS}" >> $GITHUB_OUTPUT
echo "Docker image tags: $TAGS"
- name: Run Buildx
run: |
docker buildx build -f DeveLanCacheUI_Backend/Dockerfile --build-arg BUILD_VERSION=${{steps.tags.outputs.version}} --platform linux/arm64,linux/amd64 ${{steps.tags.outputs.tags}} ${{ (github.event_name != 'pull_request' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)) && '--push' || '' }} .
build_linux:
needs: generate_version_number
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
- name: dotnet restore
run: dotnet restore DeveLanCacheUI_Backend.sln
- name: dotnet build
run: dotnet build DeveLanCacheUI_Backend.sln -c Release --no-restore /p:Version=1.0.${{needs.generate_version_number.outputs.build_number}}
- name: dotnet test
run: dotnet test DeveLanCacheUI_Backend.sln -c Release --no-build --verbosity normal
build_windows:
needs: generate_version_number
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET Core @ Latest
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '19' # The JDK version to make available on the path.
java-package: jdk # (jre, jdk, or jdk+fx) - defaults to jdk
architecture: x64 # (x64 or x86) - defaults to x64
- name: Install tools
run: |
dotnet tool install --global dotnet-sonarscanner
dotnet tool install --global dotnet-reportgenerator-globaltool
- name: dotnet restore
run: dotnet restore DeveLanCacheUI_Backend.sln
- name: SonarQube begin
run: dotnet-sonarscanner begin /k:"DeveLanCacheUI_Backend" /o:"devedse-github" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.login=${{secrets.SONARQUBETOKEN}} /d:sonar.cs.opencover.reportsPaths=".\DeveLanCacheUI_Backend.Tests\TestResults\*\coverage.opencover.xml" /d:sonar.coverage.exclusions="DeveLanCacheUI_Backend.Tests/**/*.cs"
- name: dotnet build
run: dotnet build DeveLanCacheUI_Backend.sln -c Release --no-restore /p:Version=1.0.${{needs.generate_version_number.outputs.build_number}}
- name: dotnet test
#run: dotnet test DeveLanCacheUI_Backend.sln --verbosity normal --no-build -c Release /p:CollectCoverage=true /p:CoverletOutputFormat=\`"cobertura,opencover\`" /p:CoverletOutput=./TestResults/Coverage/
run: dotnet test DeveLanCacheUI_Backend.sln --verbosity normal --no-build -c Release --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura,opencover
- name: SonarQube end
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: dotnet-sonarscanner end /d:sonar.login=${{secrets.SONARQUBETOKEN}}
- name: Run CodeCov
uses: codecov/codecov-action@v4
with:
directory: ./DeveLanCacheUI_Backend.Tests/TestResults
fail_ci_if_error: true # optional (default = false)
verbose: true # optional (default = false)
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
# - uses: actions/upload-artifact@v3
# with:
# name: DeveLanCacheUI_Backend7z
# path: ./Scripts/Output/DeveLanCacheUI_Backend.7z
# - uses: actions/upload-artifact@v3
# with:
# name: DeveLanCacheUI_BackendZip
# path: ./Scripts/Output/DeveLanCacheUI_Backend.zip
# release_github:
# needs: [generate_version_number, build_windows, build_linux, build_docker]
# runs-on: ubuntu-latest
# if: github.ref == 'refs/heads/master'
# steps:
# - name: Download all artifacts
# uses: actions/download-artifact@v2
# with:
# path: ./artifacts/
# - name: Display structure of downloaded files
# run: |
# cd ./artifacts/
# ls -R
# - name: Create Release
# id: create_release
# uses: actions/create-release@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
# with:
# tag_name: 1.0.${{needs.generate_version_number.outputs.build_number}}
# release_name: 1.0.${{needs.generate_version_number.outputs.build_number}}
# body: |
# ${{ github.event.head_commit.message }}
# draft: false
# prerelease: false
# - name: Release
# uses: softprops/action-gh-release@v1
# with:
# tag_name: 1.0.${{needs.generate_version_number.outputs.build_number}}
# files: |
# ./artifacts/DeveLanCacheUI_Backend7z/DeveLanCacheUI_Backend.7z
# ./artifacts/DeveLanCacheUI_BackendZip/DeveLanCacheUI_Backend.zip
# ./artifacts/DeveLanCacheUI_BackendNuGet/*.nupkg
# ./artifacts/DeveLanCacheUI_BackendNuGet/*.snupkg
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# release_nuget:
# needs: [generate_version_number, build_windows, build_linux, build_docker, release_github]
# runs-on: ubuntu-latest
# if: github.ref == 'refs/heads/master'
# steps:
# - name: Download all artifacts
# uses: actions/download-artifact@v2
# with:
# name: DeveLanCacheUI_BackendNuGet
# path: ./artifacts/DeveLanCacheUI_BackendNuGet/
# - name: Push NuGet
# run: dotnet nuget push ./artifacts/DeveLanCacheUI_BackendNuGet/DeveLanCacheUI_Backend.1.0.${{needs.generate_version_number.outputs.build_number}}.nupkg -k ${{ secrets.NUGETTOKEN }} -s https://api.nuget.org/v3/index.json
comment-on-pr:
needs: [build_docker, build_linux, build_windows]
runs-on: ubuntu-latest
if: github.event_name == 'workflow_run'
steps:
- name: Get PR number
id: get_pr
run: |
PR_NUMBER=$(echo "${{ github.event.workflow_run.pull_requests[0].number }}")
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
- name: Create comment body
id: comment_body
run: |
RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
IMAGE_TAG="${{ steps.tags.outputs.tags }}"
BODY=":rocket: [Full build workflow run]($RUN_URL) has completed."
if [ "${{ needs.build_docker.result }}" = "success" ] && [ "${{ needs.build_linux.result }}" = "success" ] && [ "${{ needs.build_windows.result }}" = "success" ]; then
BODY="$BODY\n\n:whale: Docker image: https://hub.docker.com/r/devedse/develancacheui_backend\nTagged as: $IMAGE_TAG"
fi
echo "body<<EOF" >> $GITHUB_OUTPUT
echo "$BODY" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Comment on PR
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ steps.get_pr.outputs.pr_number }}
body: ${{ steps.comment_body.outputs.body }}