From f1a4b0e8f5476d876882c7c4474157e074399ab2 Mon Sep 17 00:00:00 2001 From: "Marco Antonio J. Costa" Date: Wed, 8 Jan 2025 18:32:26 -0300 Subject: [PATCH] just the build --- .github/workflows/build.yml | 254 ++++++--------------------- .github/workflows/build_language.yml | 216 ----------------------- 2 files changed, 55 insertions(+), 415 deletions(-) delete mode 100644 .github/workflows/build_language.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c25feead0..1a6954542 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,219 +1,75 @@ -name: build - on: + pull_request: push: - branches: - - '**' tags: - 'v*' - # allows to manually trigger a build workflow_dispatch: inputs: - build_all_languages: - description: build all languages - required: false - default: false - type: boolean - assemble_release: - description: create release - required: false - default: false - type: boolean - -permissions: - contents: write + manualTrigger: + description: trigger a PR or release run + required: true + default: pr + type: choice + options: + - pr + - release jobs: - workflow_setup: + compile: + if: > + (github.event_name == 'pull_request') || + (github.event_name == 'workflow_dispatch' && github.event.inputs.manualTrigger == 'pr') runs-on: ubuntu-latest - outputs: - languages_json_array: ${{ steps.global_vars.outputs.languages_json_array }} - assemble_release: ${{ steps.global_vars.outputs.assemble_release }} steps: - - id: global_vars - name: Set global variables - run: | - set -eux - - full_release='${{ ( github.repository == '1dot13/source' && github.ref_name == 'master' ) || startsWith(github.ref, 'refs/tags/v') }}' - - if [[ '${{ inputs.build_all_languages }}' == 'true' || ( '${{ inputs.build_all_languages }}' == '' && "$full_release" == 'true' ) ]] - then - languages_json_array='["Chinese", "German", "English", "French", "Polish", "Italian", "Dutch", "Russian"]'; - else - # English + some other language for compilation testing - languages_json_array='["German", "English"]' - fi - echo "languages_json_array=$languages_json_array" >> $GITHUB_OUTPUT - - if [[ '${{ inputs.assemble_release }}' == 'true' || ( '${{ inputs.assemble_release }}' == '' && "$full_release" == 'true' ) ]] - then - assemble_release='true' - else - assemble_release='false' - fi - echo "assemble_release=$assemble_release" >> $GITHUB_OUTPUT + - name: Install needed packages + run: >- + sudo apt-get update && + sudo apt-get install -y --no-install-recommends --no-install-suggests --no-upgrade + msitools libgcab-dev winbind ninja-build wine-stable git - - name: Clone repos metadata - run: | - set -eux - - GAMEDIR_REPOSITORY=1dot13/gamedir - GAMEDIR_LANGUAGES_REPOSITORY=1dot13/gamedir-languages - - # filter tree is what makes this fast - git clone --config transfer.fsckobjects=false --tags --no-checkout --filter=tree:0 \ - "https://github.com/$GITHUB_REPOSITORY" \ - source - - git clone --config transfer.fsckobjects=false --no-checkout --filter=tree:0 \ - https://github.com/$GAMEDIR_REPOSITORY \ - gamedir - - git clone --config transfer.fsckobjects=false --no-checkout --filter=tree:0 \ - https://github.com/$GAMEDIR_LANGUAGES_REPOSITORY \ - gamedir-languages - - mkdir dist/ - echo -n " - GAMEDIR_REPOSITORY=$GAMEDIR_REPOSITORY - GAMEDIR_LANGUAGES_REPOSITORY=$GAMEDIR_LANGUAGES_REPOSITORY - " > dist/versions.env + - name: Cache msvc-wine + id: msvc-wine-cache + uses: actions/cache@v4 + with: + path: msvc-wine + key: msvc-wine-cache-key - - name: Generate source version information - working-directory: source - run: | + - name: Download and install msvc-wine + if: steps.msvc-wine-cache.outputs.cache-hit != 'true' + run: |- set -eux - - SOURCE_COMMIT_DATETIME=$(TZ=UTC0 git log -1 --date=iso-strict-local --format=%cd $GITHUB_SHA) - SOURCE_COMMIT_DATE=$(TZ=UTC0 git log -1 --date=short-local --format=%cd $GITHUB_SHA) - - # GAME_VERSION is used to detect outdated save games and is the main version used for tracking - if [[ "$GITHUB_REF_TYPE" == 'tag' ]] - then - # if we build for a specific tag, use that as the game version - # examples: - # - v1.13.1 - # - v1.13.2-rc2 - GAME_VERSION="$GITHUB_REF_NAME" - else - # uses `git describe`, which tries to find a tag in the commit hierarchy. or fall back to a v1.13 version - # example five (5) commits after v1.13: - # - v1.13-5-7g7ffa - GAME_VERSION="$(git describe --tags --match='v[0-9]*' $GITHUB_SHA || echo v0-$(git rev-list --skip 1 --count $GITHUB_SHA)-g${GITHUB_SHA:0:8})" - fi - # max 15 CHAR8 - GAME_VERSION="${GAME_VERSION:0:15}" - - GAME_BUILD_INFORMATION="$SOURCE_COMMIT_DATE GitHub $GITHUB_REPOSITORY" - # in case of a branch or if the tag is truncated - if [[ "$GAME_VERSION" != *"$GITHUB_REF_NAME"* ]] - then - GAME_BUILD_INFORMATION="$GAME_BUILD_INFORMATION $GITHUB_REF_TYPE $GITHUB_REF_NAME" - fi - # max 255 CHAR16 - GAME_BUILD_INFORMATION="${GAME_BUILD_INFORMATION:0:255}" - - echo -n " - SOURCE_COMMIT_DATETIME=$SOURCE_COMMIT_DATETIME - GAME_VERSION=$GAME_VERSION - GAME_BUILD_INFORMATION=$GAME_BUILD_INFORMATION - " >> ../dist/versions.env + git clone https://github.com/mstorsjo/msvc-wine.git msvc-wine + cd msvc-wine + ./vsdownload.py --dest msvc --accept-license + ./install.sh msvc - # due to building everything in parallel, versions should be pinned at the start so everything builds based on the same versions - - name: Generate gamedir version information - working-directory: gamedir - run: | + - name: Add msvc-wine to path + run: |- set -eux - - GAMEDIR_COMMIT_SHA=$(git rev-parse HEAD) - GAMEDIR_COMMIT_DATETIME=$(TZ=UTC0 git log -1 --date=iso-strict-local --format=%cd $GAMEDIR_COMMIT_SHA) - - echo -n " - GAMEDIR_COMMIT_SHA=$GAMEDIR_COMMIT_SHA - GAMEDIR_COMMIT_DATETIME=$GAMEDIR_COMMIT_DATETIME - " >> ../dist/versions.env - - # due to building everything in parallel, versions should be pinned at the start so everything builds based on the same versions - - name: Generate gamedir-languages version information - working-directory: gamedir-languages - run: | + cd msvc-wine/msvc/bin/x86 + echo "$PWD" >> "$GITHUB_PATH" + - name: pull source + run: |- set -eux - - GAMEDIR_LANGUAGES_COMMIT_SHA=$(git rev-parse HEAD) - GAMEDIR_LANGUAGES_COMMIT_DATETIME=$(TZ=UTC0 git log -1 --date=iso-strict-local --format=%cd $GAMEDIR_LANGUAGES_COMMIT_SHA) - - echo -n " - GAMEDIR_LANGUAGES_COMMIT_SHA=$GAMEDIR_LANGUAGES_COMMIT_SHA - GAMEDIR_LANGUAGES_COMMIT_DATETIME=$GAMEDIR_LANGUAGES_COMMIT_DATETIME - " >> ../dist/versions.env + git clone https://github.com/1dot13/source --single-branch --branch master source - - name: Show version information summary - run: | - set -eux - cat dist/versions.env + - name: look for msvc + run: >- + find msvc-wine + - name: look for source + run: >- + find source + - name: Build + run: |- + cmake --build build/ --config Release -- -v - - name: Upload - uses: actions/upload-artifact@v4 - with: - name: versions.env - path: dist/ - - build: - needs: [ workflow_setup ] - strategy: - fail-fast: false - matrix: - language: ${{ fromJson(needs.workflow_setup.outputs.languages_json_array) }} - uses: ./.github/workflows/build_language.yml - with: - language: ${{ matrix.language }} - assemble: ${{ needs.workflow_setup.outputs.assemble_release == 'true' }} - # at least English and some other lang have to work - continue-on-error: ${{ matrix.language != 'English' && matrix.language != 'German' }} - - release: - needs: [ workflow_setup, build ] - if: needs.workflow_setup.outputs.assemble_release == 'true' + assemble: + if: > + (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') == 'true') || + (github.event_name == 'workflow_dispatch' && github.event.inputs.manualTrigger == 'release') + needs: [ compile ] runs-on: ubuntu-latest - steps: - - name: Download artifacts - uses: actions/download-artifact@v4 - with: - path: dist - pattern: '*_release' - merge-multiple: true - - - name: Checkout Repo - if: github.ref == 'refs/heads/master' - uses: actions/checkout@v4 - with: - path: source - fetch-depth: 1 - sparse-checkout: 'README.md' - - name: Create latest pre-release - if: github.ref == 'refs/heads/master' - working-directory: source - run: | - gh release delete latest --cleanup-tag || true - git tag -d latest || true - git push --delete origin refs/tags/latest || true - git tag latest - git push --force origin refs/tags/latest - gh release create latest ../dist/* \ - --generate-notes \ - --title "Latest (unstable)" \ - --verify-tag \ - --prerelease - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Upload to tagged release - if: startsWith(github.ref, 'refs/tags/v') - working-directory: source - run: | - exit 0 - gh release upload "$GITHUB_REF_NAME" ../dist/* --clobber - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Test manual release + run: >- + echo ${{github.event.inputs.manualTrigger}} diff --git a/.github/workflows/build_language.yml b/.github/workflows/build_language.yml deleted file mode 100644 index 0f97c7339..000000000 --- a/.github/workflows/build_language.yml +++ /dev/null @@ -1,216 +0,0 @@ -name: build language - -on: - workflow_call: - inputs: - language: - description: 'any of Chinese German English French Polish Italian Dutch Russian' - required: true - default: 'English' - type: string - assemble: - description: 'assemble full package' - required: true - default: true - type: boolean - continue-on-error: - description: 'allows a language to fail, used when building all languages' - required: false - default: false - type: boolean - -jobs: - compile: - runs-on: windows-latest # required for msbuild - continue-on-error: ${{ inputs.continue-on-error }} - strategy: - fail-fast: false - matrix: - application: [ja2, ja2mapeditor, ja2ub, ja2ubmapeditor] - - steps: - - name: Checkout source - uses: actions/checkout@v4 - - - name: Download versions.env - uses: actions/download-artifact@v4 - with: - name: versions.env - path: artifacts - - name: Restore versions.env - shell: bash - run: cat artifacts/versions.env >> $GITHUB_ENV - - # TODO: Move this into CMake, just taking the GitHub Actions parameters as -D variables - - name: Update GameVersion.cpp - shell: bash - run: | - set -eux - INPUTS_LANGUAGE=${{ inputs.language }} - GAME_VERSION=$(echo "$GAME_VERSION" | tr -cd '[:print:]' | tr -d '"\\') - GAME_BUILD="${INPUTS_LANGUAGE:0:2} $GAME_BUILD_INFORMATION" - GAME_BUILD=$(echo "$GAME_BUILD" | tr -cd '[:print:]' | tr -d '"\\') - sed -i "s|@Version@|${GAME_VERSION:0:15}|" Ja2/GameVersion.cpp - sed -i "s|@Build@|${GAME_BUILD:0:255}|" Ja2/GameVersion.cpp - cat Ja2/GameVersion.cpp - - - name: Turn on link-time optimization? - if: fromJSON(inputs.assemble) - shell: bash - run: | - set -eux - - echo " - LTO=ON - " >> $GITHUB_ENV - - - name: Prepare build properties - shell: bash - run: | - set -eux - - touch CMakePresets.json - - JA2Language=$(echo '${{ inputs.language }}' | tr '[:lower:]' '[:upper:]') - JA2Application=$(echo '${{ matrix.application }}' | tr '[:lower:]' '[:upper:]') - - echo " - JA2Language=$JA2Language - JA2Application=$JA2Application - " >> $GITHUB_ENV - - - uses: microsoft/setup-msbuild@v2 - with: - msbuild-architecture: x86 - - uses: ilammy/msvc-dev-cmd@v1 - with: - arch: x86 - - name: Prepare build - run: | - cmake -S . -B build -GNinja -DCMAKE_BUILD_TYPE=Release -DLanguages="$Env:JA2Language" -DApplications="$Env:JA2Application" -DLTO_OPTION="$Env:LTO" - - name: Build - run: | - cmake --build build/ -- -v - - name: List build artifacts - shell: bash - run: | - find build/ - - - name: Upload - uses: actions/upload-artifact@v4 - with: - name: ${{ inputs.language }}_${{ matrix.application }} - path: build/*.exe - - assemble: - needs: [ compile ] - if: inputs.assemble - runs-on: windows-latest # required for case-insensitive filesystem handling - continue-on-error: ${{ inputs.continue-on-error }} - - steps: - - name: Download versions.env - uses: actions/download-artifact@v4 - with: - name: versions.env - path: artifacts - - name: Restore versions.env - shell: bash - run: cat artifacts/versions.env >> $GITHUB_ENV - - - name: Checkout gamedir - uses: actions/checkout@v4 - with: - repository: ${{ env.GAMEDIR_REPOSITORY }} - ref: ${{ env.GAMEDIR_COMMIT_SHA }} - path: gamedir - - - name: Checkout gamedir-languages - if: inputs.language != 'English' - uses: actions/checkout@v4 - with: - repository: ${{ env.GAMEDIR_LANGUAGES_REPOSITORY }} - ref: ${{ env.GAMEDIR_LANGUAGES_COMMIT_SHA }} - path: gamedir-languages - - - name: Copy gamedir-languages files to gamedir - if: inputs.language != 'English' - shell: bash - run: | - set -eux - cp -a gamedir-languages/${{ inputs.language }}_Version/* gamedir/ - - - name: Download ja2 - uses: actions/download-artifact@v4 - with: - name: ${{ inputs.language }}_ja2 - path: artifacts/ja2 - - - name: Download ja2mapeditor - uses: actions/download-artifact@v4 - with: - name: ${{ inputs.language }}_ja2mapeditor - path: artifacts/ja2mapeditor - - - name: Download ja2ub - uses: actions/download-artifact@v4 - with: - name: ${{ inputs.language }}_ja2ub - path: artifacts/ja2ub - - - name: Download ja2ubmapeditor - uses: actions/download-artifact@v4 - with: - name: ${{ inputs.language }}_ja2ubmapeditor - path: artifacts/ja2ubmapeditor - - - name: Copy application files to gamedir - shell: bash - run: | - set -eux - for APP in ja2 ja2mapeditor ja2ub ja2ubmapeditor - do - mv artifacts/${APP}/*.exe gamedir/${APP}.exe - done - - - name: Create version information file - shell: bash - run: | - set -eux - - # "-" separates words, "_" combines words, see double-click behavior - DIST_PREFIX='JA2_113' - DIST_NAME="${DIST_PREFIX}-${GAME_VERSION}-G${GAMEDIR_COMMIT_SHA:0:4}L${GAMEDIR_LANGUAGES_COMMIT_SHA:0:4}-${{ inputs.language }}" - echo "DIST_NAME=$DIST_NAME" >> $GITHUB_ENV - - echo "If you encounter problems during gameplay, please provide the following version information: - Distribution Name: $DIST_NAME - Game Version: $GAME_VERSION - Language: ${{ inputs.language }} - Build Information: $GAME_BUILD_INFORMATION - Source Repository: $GITHUB_REPOSITORY - Source Commit SHA: $GITHUB_SHA - Source Commit Date: $SOURCE_COMMIT_DATETIME - Gamedir Repository: $GAMEDIR_REPOSITORY - Gamedir Commit SHA: $GAMEDIR_COMMIT_SHA - Gamedir Commit Date: $GAMEDIR_COMMIT_DATETIME - Gamedir Languages Repository: $GAMEDIR_LANGUAGES_REPOSITORY - Gamedir Languages Commit SHA: $GAMEDIR_LANGUAGES_COMMIT_SHA - Gamedir Languages Commit Date: $GAMEDIR_LANGUAGES_COMMIT_DATETIME - " > "gamedir/${DIST_PREFIX}-Version.txt" - cat "gamedir/${DIST_PREFIX}-Version.txt" - - - name: Create release archive - shell: bash - run: | - set -eux - mkdir dist/ - cd gamedir/ - 7z a -bb -xr'!.*' "../dist/${DIST_NAME}.7z" . - - - name: Upload - uses: actions/upload-artifact@v4 - with: - name: ${{ inputs.language }}_release - path: dist/ - compression-level: 0