From d0eda30185bcc442b85971d6e03e2e20f97d58f7 Mon Sep 17 00:00:00 2001 From: Frostebite Date: Sun, 17 Apr 2022 01:45:36 +0100 Subject: [PATCH] self hosted runner pipeline --- .../cloud-runner-self-hosted-ephemeral.yml | 124 ++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 .github/workflows/cloud-runner-self-hosted-ephemeral.yml diff --git a/.github/workflows/cloud-runner-self-hosted-ephemeral.yml b/.github/workflows/cloud-runner-self-hosted-ephemeral.yml new file mode 100644 index 00000000..4cd11af1 --- /dev/null +++ b/.github/workflows/cloud-runner-self-hosted-ephemeral.yml @@ -0,0 +1,124 @@ +# This is a basic workflow to help you get started with Actions + +name: Cloud Runner - AWS Self-Hosted Ephemeral Runner Pipeline + +env: + AWS_REGION: eu-west-2 + AWS_DEFAULT_REGION: eu-west-2 + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + CLOUD_RUNNER_BRANCH: cloud-runner-develop + UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the develop branch + push: { branches: [main, cloud-runner-develop] } + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + boot-self-hosted-runner: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + - uses: google-github-actions/setup-gcloud@v0 + with: + version: '288.0.0' + service_account_email: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_EMAIL }} + service_account_key: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_KEY }} + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + with: + lfs: 'false' + fetch-depth: 0 + ########################### + # Ephemeral Runner # + ########################### + - name: Unity - Builder + # You may pin to the exact commit or the version. + # uses: game-ci/unity-builder@3d0eb0805bbe2df90e319abbe42e41d0b9105625 + uses: game-ci/unity-builder@cloud-runner-develop + with: + cloudRunnerCluster: aws + allowDirtyBuild: true + cloudRunnerMemory: 4096 + cloudRunnerCpu: 2048 + gitPrivateToken: ${{ secrets.GITHUB_TOKEN }} + targetPlatform: StandaloneWindows64 + customJob: | + - name: upload + image: ubuntu + commands: | + export DEBIAN_FRONTEND=noninteractive + export RUNNER_ALLOW_RUNASROOT="1" + apt-get update + apt-get install -qy unzip curl libdigest-sha-perl apt-transport-https libicu-dev jq git git-lfs + mkdir -p $BUILD_GUID/actions-runner && cd $BUILD_GUID/actions-runner + curl -o actions-runner-linux-x64-2.289.2.tar.gz -L https://github.com/actions/runner/releases/download/v2.289.2/actions-runner-linux-x64-2.289.2.tar.gz + echo "7ba89bb75397896a76e98197633c087a9499d4c1db7603f21910e135b0d0a238 actions-runner-linux-x64-2.289.2.tar.gz" | shasum -a 256 -c + tar xzf ./actions-runner-linux-x64-2.289.2.tar.gz + repo="game-ci/unity-builder" + TOKEN=$(curl -X POST -H "Authorization: Bearer $GIT_PRIVATE_TOKEN" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/$repo/actions/runners/registration-token | jq -r .token) + ./config.sh --url https://github.com/$repo --token $TOKEN --ephemeral + echo "cloud runner stop watching job" + ./run.sh + boot-game-ci-cloud-runner: + runs-on: self-hosted + steps: + - uses: actions/checkout@v2 + with: + lfs: false + fetch-depth: 0 + - name: Unity - Builder + id: aws-fargate-unity-build + # You may pin to the exact commit or the version. + # uses: game-ci/unity-builder@3d0eb0805bbe2df90e319abbe42e41d0b9105625 + uses: game-ci/unity-builder@cloud-runner-develop + with: + cloudRunnerCluster: aws + allowDirtyBuild: true + cloudRunnerMemory: 8192 + cloudRunnerCpu: 2048 + gitPrivateToken: ${{ secrets.GITHUB_TOKEN }} + targetPlatform: StandaloneWindows64 + postBuildSteps: | + - name: upload + image: amazon/aws-cli + commands: | + aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile default + aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile default + aws configure set region $AWS_DEFAULT_REGION --profile default + aws s3 ls + aws s3 ls game-ci-test-storage + du -s /data/cache/$CACHE_KEY + echo "build folder contents" + du -s /data/cache/$CACHE_KEY/build + find ~ -name '*exe' + aws s3 cp /data/cache/$CACHE_KEY/build/build-$BUILD_GUID.zip s3://game-ci-test-storage/$CACHE_KEY/build-$BUILD_GUID.zip + secrets: + - name: awsAccessKeyId + value: ${{ secrets.AWS_ACCESS_KEY_ID }} + - name: awsSecretAccessKey + value: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + - name: awsDefaultRegion + value: eu-west-2 + ########################### + # Download Artifacts # + ########################### + # download from cloud storage + - run: | + aws s3 cp s3://game-ci-test-storage/${{ steps.aws-fargate-unity-build.outputs.CACHE_KEY }}/build-${{ steps.aws-fargate-unity-build.outputs.BUILD_GUID }}.zip build-${{ steps.aws-fargate-unity-build.outputs.BUILD_GUID }}.zip + unzip build-${{ steps.aws-fargate-unity-build.outputs.BUILD_GUID }}.zip -d build + ls build + ########################### + # Upload # + ########################### + # download from cloud storage + - uses: actions/upload-artifact@v2 + with: + name: AWS Build (${{ matrix.targetPlatform }}) + path: build-${{ steps.aws-fargate-unity-build.outputs.BUILD_GUID }}.zip + retention-days: 14