Deploy #2380
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy | |
on: | |
workflow_dispatch: | |
inputs: | |
action: | |
description: action (deploy/restart/stop) | |
required: true | |
default: restart | |
branch: | |
description: branch, meaning server instance (sweetpie/indev) | |
required: true | |
default: indev | |
env: | |
BUILD_TYPE: RelWithDebInfo | |
GAMEMODE_GITHUB_TOKEN: ${{secrets.GAMEMODE_GITHUB_TOKEN}} | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get action | |
run: | | |
echo "DEPLOY_BRANCH=${{github.event.inputs.branch}}" >> "$GITHUB_ENV" | |
echo "DEPLOY_ACTION=${{github.event.inputs.action}}" >> "$GITHUB_ENV" | |
- name: Checkout (full) | |
if: ${{env.DEPLOY_ACTION == 'deploy'}} | |
uses: actions/checkout@v2 | |
with: | |
submodules: recursive | |
fetch-depth: 0 | |
- name: Checkout (last commit) | |
if: ${{env.DEPLOY_ACTION != 'deploy'}} | |
uses: actions/checkout@v2 | |
with: | |
submodules: recursive | |
fetch-depth: 0 | |
- name: Gather PRs | |
if: ${{env.DEPLOY_ACTION == 'deploy'}} | |
env: | |
DEPLOY_STATUS_WEBHOOK: ${{secrets.DEPLOY_STATUS_WEBHOOK}} | |
run: | | |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
git config pull.rebase false | |
base_rev="`git rev-parse HEAD`" | |
echo "=== Base revision: $base_rev" | |
git checkout -b tmp | |
yarn --cwd="${{github.workspace}}/misc/deploy/gather-server-branch" | |
./misc/deploy/gather_server_branch.sh | |
echo "" | |
echo "=== Changes since $base_rev:" | |
git log -p "$base_rev.." | tee deploy_git_log | |
echo "" | |
echo "=== Full diff being deployed:" | |
git diff "$base_rev" | tee deploy_git_diff | |
- name: Upload patches | |
if: ${{env.DEPLOY_ACTION == 'deploy'}} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: patches | |
path: | | |
deploy_git_log | |
deploy_git_diff | |
- name: Post link | |
if: ${{env.DEPLOY_ACTION == 'deploy'}} | |
env: | |
DEPLOY_STATUS_WEBHOOK: ${{secrets.DEPLOY_STATUS_WEBHOOK}} | |
run: | | |
link="${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}" | |
./misc/deploy/call_webhook.sh "Started build. " \ | |
"You can follow the process at <$link>. " \ | |
"Once build is finished, further progress will be reported here." | |
- name: Get image to build upon | |
run: | | |
cat ${{github.workspace}}/misc/github_env_linux >> "$GITHUB_ENV" | |
- name: Prepare for build | |
if: ${{env.DEPLOY_ACTION == 'deploy'}} | |
uses: addnab/docker-run-action@v3 | |
with: | |
image: ${{ env.SKYMP_VCPKG_DEPS_IMAGE }} | |
options: | | |
-v ${{github.workspace}}:/src | |
-v ${{github.workspace}}/.cmake-js:/home/skymp/.cmake-js | |
run: | | |
chown -R skymp:skymp /src /home/skymp/.cmake-js | |
- name: Wait for other runs to complete | |
run: | | |
attempt_counter=0 | |
until [[ "$(gh api repos/Pospelove/skymp5-gamemode/actions/runs --jq '[.workflow_runs[] | select(.status == "in_progress" or .status == "queued") | select(.workflow_file.path == ".github/workflows/merge-to.yml")]' | jq length)" == "0" || "$attempt_counter" -ge "10" ]]; do | |
echo "Waiting for other runs to complete... Attempt: $attempt_counter" | |
sleep 10 | |
attempt_counter=$((attempt_counter+1)) | |
done | |
env: | |
GH_TOKEN: ${{env.GAMEMODE_GITHUB_TOKEN}} | |
shell: bash | |
- name: CMake Configure | |
if: ${{env.DEPLOY_ACTION == 'deploy'}} | |
uses: addnab/docker-run-action@v3 | |
with: | |
image: ${{ env.SKYMP_VCPKG_DEPS_IMAGE }} | |
options: | | |
-v ${{github.workspace}}:/src | |
-v ${{github.workspace}}/.cmake-js:/home/skymp/.cmake-js | |
-u skymp | |
run: | | |
cd /src \ | |
&& ./build.sh --configure \ | |
-DBUILD_UNIT_TESTS=OFF \ | |
-DBUILD_GAMEMODE=ON \ | |
-DOFFLINE_MODE=OFF \ | |
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \ | |
-DGITHUB_TOKEN=${{env.GAMEMODE_GITHUB_TOKEN}} | |
- name: Upload compile_commands.json | |
uses: actions/upload-artifact@v3 | |
with: | |
name: compile_commands.json | |
path: ${{github.workspace}}/build/compile_commands.json | |
- name: Build | |
if: ${{env.DEPLOY_ACTION == 'deploy'}} | |
uses: addnab/docker-run-action@v3 | |
with: | |
image: ${{ env.SKYMP_VCPKG_DEPS_IMAGE }} | |
options: | | |
-v ${{github.workspace}}:/src | |
-v ${{github.workspace}}/.cmake-js:/home/skymp/.cmake-js | |
-u skymp | |
run: | | |
cd /src \ | |
&& ./build.sh --build | |
- name: Deploy | |
env: | |
DEPLOY_STATUS_WEBHOOK: ${{secrets.DEPLOY_STATUS_WEBHOOK}} | |
DEPLOY_TARGET_HOST: ${{secrets.DEPLOY_TARGET_HOST}} | |
DEPLOY_TARGET_USER: skmp | |
DEPLOY_SSH_PRIVATE_KEY: ${{secrets.DEPLOY_SSH_PRIVATE_KEY}} | |
DEPLOY_SSH_KNOWN_HOSTS: ${{secrets.DEPLOY_SSH_KNOWN_HOSTS}} | |
run: | | |
./misc/deploy/push_branch_to_server.sh | |
- name: Notify failure | |
env: | |
DEPLOY_STATUS_WEBHOOK: ${{secrets.DEPLOY_STATUS_WEBHOOK}} | |
if: '!success()' | |
run: | | |
link="${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}" | |
./misc/deploy/call_webhook.sh \ | |
"Build or deploy failed or was cancelled. " \ | |
"Check out the logs at <$link> to find out why." |