From 9091480cdc832cb2d5b214be80cf47ce1001657e Mon Sep 17 00:00:00 2001 From: cdozdil <35529761+cdozdil@users.noreply.github.com> Date: Tue, 21 Jan 2025 12:04:20 +0300 Subject: [PATCH] Create test.yml --- .github/workflows/test.yml | 170 +++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..c1620f99 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,170 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Test + +on: + workflow_dispatch: +# push: +# branches: [ "master" ] +# pull_request: +# branches: [ "master" ] + +env: + # Path to the solution file relative to the root of the project. + SOLUTION_FILE_PATH: . + + # Configuration type to build. + # You can convert this to a build matrix if you need coverage of multiple configuration types. + # https://docs.github.com/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + BUILD_CONFIGURATION: Release + +permissions: + contents: write + +jobs: + build: + runs-on: windows-latest + + steps: + - uses: actions/checkout@v4 + with: + submodules: 'true' + + - name: Extract Version + id: get_version + working-directory: ${{ github.workspace }} + shell: powershell + run: | + # Ensure the file exists before proceeding + $resourceFile = ".\OptiScaler\resource.h" + if (-Not (Test-Path $resourceFile)) { + Write-Error "File not found: $resourceFile" + exit 1 + } + + # Helper function to extract the first matching line for a version component + function Get-Version-Component { + param ( + [string]$pattern, + [string]$replacement + ) + # Use Select-String and take only the first match + $line = Get-Content $resourceFile | Select-String -Pattern $pattern | Select-Object -First 1 + if ($line) { + return ($line.Line -replace $replacement).Trim() + } else { + Write-Error "Pattern not found: $pattern" + exit 1 + } + } + + # Extract version components (only the first match for each pattern) + $majorVersion = Get-Version-Component 'VER_MAJOR_VERSION' '#define VER_MAJOR_VERSION\s+' + $minorVersion = Get-Version-Component 'VER_MINOR_VERSION' '#define VER_MINOR_VERSION\s+' + $hotfixVersion = Get-Version-Component 'VER_HOTFIX_VERSION' '#define VER_HOTFIX_VERSION\s+' + $buildVersion = Get-Version-Component 'VER_BUILD_NUMBER' '#define VER_BUILD_NUMBER\s+' + + # Merge into a single version string + $version = "v$majorVersion.$minorVersion.$hotfixVersion-pre$buildVersion" + + # Get the current date in a specific format (e.g., YYYYMMDD) + $date = Get-Date -Format "yyyyMMdd" + + # Construct the output filename with version and date + $outputFileName = "OptiScaler_${version}_${date}" + + # Output the generated filename + Write-Output "Generated Filename: $outputFileName" + + # Write outputs to GITHUB_OUTPUT + "version=$version" | Out-File -FilePath $env:GITHUB_OUTPUT -Append + "filename=$outputFileName" | Out-File -FilePath $env:GITHUB_OUTPUT -Append + + continue-on-error: false + + - name: Debug Outputs + run: | + echo "Version: ${{ steps.get_version.outputs.version }}" + echo "Filename: ${{ steps.get_version.outputs.filename }}" + + - name: Check Existing Release + id: check_release + uses: actions/github-script@v6 + with: + script: | + const releaseTag = "nightly"; + try { + const release = await github.rest.repos.getReleaseByTag({ + owner: context.repo.owner, + repo: context.repo.repo, + tag: releaseTag, + }); + core.setOutput("release_exists", true); + core.setOutput("release_id", release.data.id); + core.setOutput("upload_url", release.data.upload_url); + } catch (error) { + if (error.status === 404) { + core.setOutput("release_exists", false); + } else { + throw error; + } + } + + - name: Create Nightly Release (if not exists) + id: create_release + if: steps.check_release.outputs.release_exists == 'false' + uses: actions/github-script@v6 + with: + script: | + const release = await github.rest.repos.createRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + tag_name: "nightly", + name: "Nightly Builds", + body: "This is an automated nightly build release.", + draft: false, + prerelease: true, + }); + core.setOutput("release_id", release.data.id); + core.setOutput("upload_url", release.data.upload_url); + + - name: Get Commit Messages From Last Day + id: commit_messages + shell: powershell + run: | + Write-Output "Fetching commits from the last 24 hours..." + + # Get commit messages from the past 24 hours + $commits = git log --since="1 day ago" --pretty=format:"%h %s (%an)" + + # If no commits are found, cancel the workflow + if ([string]::IsNullOrEmpty($commits)) { + Write-Output "No commits in the last 24 hours. Cancelling workflow." + exit 0 + } + + # Write the commits to the output + $output = "commits=$commits" + $output | Out-File -FilePath $env:GITHUB_OUTPUT -Append + + - name: Generate Release Notes + id: release_notes + shell: powershell + run: | + $commits = "${{ steps.commit_messages.outputs.commits }}" + $releaseNotes = "### Changes in the Last 24 Hours`n`n$commits" + + # Output the release notes to the console + Write-Output $releaseNotes + + # Write the release notes to GITHUB_OUTPUT for subsequent steps + "release_notes=$releaseNotes" | Out-File -FilePath $env:GITHUB_OUTPUT -Append + + - name: Debug Outputs + run: | + echo "Release notes: ${{ steps.release_notes.outputs.release_notes }}" + +