OrchidIsle / UE5-Build-Project

31 stars 3 forks source link

More options for specific use cases and fixed an issue regarding the "archiveDirectory" input. #14

Closed Minimata closed 7 months ago

Minimata commented 7 months ago

TL;DR

Hi, I wanted to use your Github Action for my project but ended up having to tweak a few things to my use cases. The changes shouldn't impact current action usage but allow for a wider variety of situations (including mine), therefore I think a PR is in order to complement your Action instead of creating a similar yet different one.

Features

Fixes

Possible improvements

Misc

Conclusion

Thank you for creating this little action which is a smooth entry into the world of Github Actions and CI/CD for Unreal Engine. I hope you'll accept the request so that we may continue to use a single action for this purpose instead of duplicating functionality in the Action marketplace. I look forward to getting your advice on the possible improvements listed above.

Cheers,

edwardteach42 commented 7 months ago

Thank you for this pull request. I will review it and merge in this weekend. On the note of improvements:

ARCHIVE_PATH=\\ORCHIDNAS\OrchidIsleGames\
RUNUAT_PATH54=C:\UnrealEngine\Engine\Build\BatchFiles\RunUAT.bat
SEVEN_Z_PATH=C:\Program Files\7-Zip\7z.exe

Here is an example of our full build process for a Win64 build:

name: Build Win64 Client

on:
  release:
    types: [created]
  push:
    branches:
      - dev

jobs:
  build:
    runs-on: [UE54]
    environment: ${{ 
        (github.ref == 'refs/heads/dev' && 'Development') || 
        (github.event_name == 'release' && startsWith(github.ref, 'refs/tags/') && contains(github.ref, '-alpha') && 'Staging') || 
        (github.event_name == 'release' && startsWith(github.ref, 'refs/tags/') && contains(github.ref, '-beta') && 'Staging') || 
        (github.event_name == 'release' && startsWith(github.ref, 'refs/tags/') && contains(github.ref, '-rc') && 'Staging') || 
        (github.event_name == 'release' && startsWith(github.ref, 'refs/tags/') && 'Production') || 
        'Development' 
      }}
    steps:
    - name: Checkout Repository
      uses: actions/checkout@v2
      with:
        token: ${{ secrets.ACCESS_TOKEN }}
        lfs: false
        fetch-depth: 0 # Fetches all history for all tags and branches
        submodules: recursive

    - name: Set Unreal Environment Variables
      run: |
        Get-Content "${{ github.workspace }}\..\..\..\.unreal" | ForEach-Object {
            $split = $_ -split '=', 2
            $name = $split[0]
            $value = $split[1]
            Add-Content -Path $env:GITHUB_ENV -Value "$name=$value"
        }

    - name: Get Project Version and Build Number
      uses: OrchidIsle/UE5-Semantic-Versioning@latest
      with:
        BUILD_PREFIX: ${{ github.ref_name }}
        CONFIG_DIR_PATH: ${{ github.workspace }}\MyProject\Config
        ADD_BUILD_INFO: true
        USE_RELEASE_BUILD: ${{ github.event_name == 'release' }}

    - name: Cook, Stage & Package UE Project
      uses: OrchidIsle/UE5-Build-Project@latest
      with:
        RUNUAT_PATH: ${{ env.RUNUAT_PATH54 }}
        UPROJECT_PATH: ${{ github.workspace }}\MyProject\MyProject.uproject
        BUILD_CONFIG: ${{ vars.BUILD_CONFIG }}
        PLATFORM: Win64
        COOK: true
        STAGE: true
        PACKAGE: true
        PAK: true
        SERVER: false
        EDITOR: true
        ENCRYPT_INI: true

    - name: Compress Win64 Client using 7-Zip
      run: |
        $7zPath = "${{ env.SEVEN_Z_PATH }}"
        $sourceDir = "${{ github.workspace }}\MyProject\Saved\StagedBuilds\Windows"
        $archiveFile = "MyProject-Win64-${{ env.BUILD_ID }}.zip"
        & "$7zPath" a -tzip "$archiveFile" "$sourceDir\*"

    - name: Copy to Archive
      run: |
        $sourcePath = "MyProject-Win64-${{ env.BUILD_ID }}.zip"
        $destinationPath = "${{ env.ARCHIVE_PATH }}\MyProject\Builds\Win64\MyProject-Win64-${{ env.BUILD_ID }}.zip" # Replace with your destination folder path
        $destinationDirectory = Split-Path -Path $destinationPath -Parent

        if (-not (Test-Path -Path $destinationDirectory)) {
            New-Item -ItemType Directory -Path $destinationDirectory
        }

        Copy-Item -Path $sourcePath -Destination $destinationPath

    - name: Upload Build to Amazon S3
      uses: NotCoffee418/s3-zip-upload@v1.4
      env:
        AWS_SECRET_ID: ${{ secrets.DOWNLOAD_AWS_KEY_ID }}
        AWS_SECRET_KEY: ${{ secrets.DOWNLOAD_AWS_SECRET_ACCESS_KEY }}
        BUCKET_NAME: ${{ secrets.DOWNLOAD_AWS_BUCKET }}
        AWS_REGION: us-east-1
        SOURCE_MODE: FILE
        SOURCE_PATH: ./MyProject-Win64-${{ env.BUILD_ID }}.zip
        DEST_FILE: MyProject/Win64/MyProject-Win64-${{ env.BUILD_ID }}.zip

    - name: Upload Latest Full Release
      if: github.event_name == 'release'
      uses: NotCoffee418/s3-zip-upload@v1.4
      env:
        AWS_SECRET_ID: ${{ secrets.DOWNLOAD_AWS_KEY_ID }}
        AWS_SECRET_KEY: ${{ secrets.DOWNLOAD_AWS_SECRET_ACCESS_KEY }}
        BUCKET_NAME: ${{ secrets.DOWNLOAD_AWS_BUCKET }}
        AWS_REGION: us-east-1
        SOURCE_MODE: FILE
        SOURCE_PATH: ./MyProject-Win64-${{ env.BUILD_ID }}.zip
        DEST_FILE: MyProject/MyProject-Win64-Latest.zip
Minimata commented 7 months ago

In regards to the Linux support [...]

Okay though I think we misunderstood each other here. I try to containerize my actions as much as possible but windows containers are difficult to work with so all my container work is done on Linux, like so:

jobs:
  RunTests:
    runs-on: ubuntu-latest
    container: ghcr.io/epicgames/unreal-engine:dev-slim-5.3.2
    # ...

The need for a Linux-based action is therefore not so much to compile and build for Linux specifically but to support this container-based approach. If you think a branch is fine then that's cool with me. Do you want me to provide you with the code for it? I'm not a shell expert but I could probably manage.

I noticed this with the PDB files. I will create a bug report and look into addressing this.

Great stuff, thanks!

For compression, we felt that it would be best utilized as a separate step in the main action.

That's fair enough.

We create a .unreal file in the root of the actions runner that is read in the Set Unreal Environment Variables step that contains:

So if I understand correctly this .unreal file is sort of a .env file that points to the relevant paths on your computer for the action to run is that it ? This suggests all of this only runs on your computer.

7Zip is interesting, I'm simply doing a Compress-Archive but 7zip is probably a better approach, I should try it out.

Here is an example of our full build process for a Win64 build:

That's so cool ! Helps a lot. I didn't think a build would work without LFS and wondered how that would go now that my checkouts take an hour but I'm definitely getting rid of downloading all large files now !

Your branch handling is interesting too though quite different from mine. I strive for a trunk-based approach and have not experimented with Development, Staging or Production builds.

Thanks for all this info and for merging as well !