diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f6f4e1f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,78 @@ +# 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: Create Release + +on: + release: + types: + - created + +env: + # Path to the solution file relative to the root of the project. + SOLUTION_FILE_PATH: . + TARGET_FILENAME: HexEdit.exe + PACKAGE_PREFIX: HexEdit + VERSION_H: src\\HexEdit\\version.h + +permissions: + contents: write + +jobs: + build: + strategy: + matrix: + configuration: [Release] + platform: [x64, Win32] + + runs-on: windows-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set variables + run: + echo "TARGET_PATH=bin\${{matrix.platform}}\${{matrix.configuration}}\${{env.TARGET_FILENAME}}" + "PACKAGE_NAME=./${{env.PACKAGE_PREFIX}}_${{matrix.configuration}}_${{matrix.platform}}.zip" + | Out-File -FilePath $env:GITHUB_ENV + + - name: Setup MSBuild + uses: microsoft/setup-msbuild@v1.1 + + - name: Increment version + shell: python + run: | + import os + import re + r = re.match(r'v(\d+)\.(\d+)\.(\d+)', '${{github.ref_name}}') + path = os.path.abspath("${{env.VERSION_H}}") + with open(path, "w") as f: + print("#define VERSION_MAJOR", r.group(1), file=f) + print("#define VERSION_MIN", r.group(2), file=f) + print("#define VERSION_BUILD", r.group(3), file=f) + print("#define VERSION_BUILD_COUNT", ${{github.run_number}}, file=f) + print("Writing: ", path) + + - name: Build + working-directory: ${{env.GITHUB_WORKSPACE}} + run: msbuild /m + /p:Configuration=${{matrix.configuration}} + /p:Platform=${{matrix.platform}} ${{env.SOLUTION_FILE_PATH}} + + - name: Package + run: + $compress = @{ + Path = "${{env.TARGET_PATH}}", "LICENCE.TXT", "README.md"; + CompressionLevel = "Optimal"; + DestinationPath = "${{env.PACKAGE_NAME}}" + }; + Compress-Archive @compress + + - name: Publish + run: gh release upload ${{github.ref_name}} ${{env.PACKAGE_NAME}} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +