Deploy #593
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 | |
concurrency: | |
group: deploy | |
on: | |
workflow_dispatch: | |
inputs: | |
ci_required: | |
description: 'CI Suite is required' | |
type: boolean | |
required: true | |
default: true | |
perform_deploy_main: | |
description: 'Deploy Paradise Main/Secondary' | |
type: boolean | |
required: true | |
default: true | |
perform_deploy_vega: | |
description: 'Deploy Paradise Vega' | |
type: boolean | |
required: true | |
default: true | |
perform_deploy_cleo: | |
description: 'Deploy Paradise Cleo' | |
type: boolean | |
required: true | |
default: true | |
perform_deploy_prime: | |
description: 'Deploy Paradise Prime' | |
type: boolean | |
required: true | |
default: false | |
perform_deploy_wl: | |
description: 'Deploy Paradise WL' | |
type: boolean | |
required: true | |
default: false | |
perform_deploy_tutorial: | |
description: 'Deploy Paradise Tutorial' | |
type: boolean | |
required: true | |
default: false | |
jobs: | |
check: | |
name: Check User Permission | |
runs-on: ubuntu-latest | |
steps: | |
- uses: skjnldsv/check-actor-permission@v3 | |
with: | |
require: 'admin' | |
CI: | |
needs: [check] | |
uses: ./.github/workflows/ci.yml # use the callable tests job to run tests | |
if: ${{ inputs.ci_required }} | |
update-isp-lists: | |
name: Update ISP Lists | |
runs-on: ubuntu-latest | |
needs: [check] | |
steps: | |
- name: Update ISP Lists | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.PRODUCTION_HOST }} | |
username: ${{ secrets.PRODUCTION_USERNAME }} | |
key: ${{ secrets.PRODUCTION_SSH_KEY }} | |
passphrase: ${{ secrets.PRODUCTION_SSH_KEY_PASS }} | |
script: /var/lib/byond/update_isp_lists.sh | |
set-matrix: | |
name: Set Deployment Matrix | |
runs-on: ubuntu-latest | |
needs: [check] | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- id: set-matrix | |
run: | | |
MATRIX_JSON="{\"include\": [" | |
if ${{ github.event.inputs.perform_deploy_main }}; then | |
MATRIX_JSON="${MATRIX_JSON}{\"environment\": \"Main\"}," | |
MATRIX_JSON="${MATRIX_JSON}{\"environment\": \"Secondary\"}," | |
fi | |
if ${{ github.event.inputs.perform_deploy_vega }}; then | |
MATRIX_JSON="${MATRIX_JSON}{\"environment\": \"Vega\"}," | |
fi | |
if ${{ github.event.inputs.perform_deploy_cleo }}; then | |
MATRIX_JSON="${MATRIX_JSON}{\"environment\": \"Cleo\"}," | |
fi | |
if ${{ github.event.inputs.perform_deploy_prime }}; then | |
MATRIX_JSON="${MATRIX_JSON}{\"environment\": \"Prime\"}," | |
fi | |
if ${{ github.event.inputs.perform_deploy_wl }}; then | |
MATRIX_JSON="${MATRIX_JSON}{\"environment\": \"WL\"}," | |
fi | |
if ${{ github.event.inputs.perform_deploy_tutorial }}; then | |
MATRIX_JSON="${MATRIX_JSON}{\"environment\": \"Tutorial\"}," | |
fi | |
MATRIX_JSON="${MATRIX_JSON%?}]}" # Remove the trailing comma | |
echo "matrix=${MATRIX_JSON}" >> $GITHUB_OUTPUT | |
deploy: | |
name: Deploy Paradise | |
runs-on: ubuntu-latest | |
permissions: | |
deployments: write | |
strategy: | |
fail-fast: false | |
matrix: ${{fromJson(needs.set-matrix.outputs.matrix)}} | |
environment: ${{ matrix.environment }} | |
needs: [check, update-isp-lists, CI, set-matrix] | |
if: always() && !cancelled() && !failure() | |
steps: | |
- uses: chrnorm/deployment-action@v2 | |
name: Create GitHub deployment | |
id: deployment | |
with: | |
token: '${{ github.token }}' | |
environment: ${{ matrix.environment }} | |
environment-url: ${{ vars.ENVIRONMENT_URL }} | |
log-url: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}' | |
ref: ${{ vars.BRANCH }} | |
production-environment: true | |
initial-status: 'in_progress' | |
- name: Update and Build Paradise Main | |
if: matrix.environment == 'Main' && inputs.perform_deploy_main | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.PRODUCTION_HOST }} | |
username: ${{ secrets.PRODUCTION_USERNAME }} | |
key: ${{ secrets.PRODUCTION_SSH_KEY }} | |
passphrase: ${{ secrets.PRODUCTION_SSH_KEY_PASS }} | |
script: | | |
TIME=$(date +'%Y-%m-%d%T') | |
sudo systemctl --wait start deploy-main | |
journalctl --since $TIME -u deploy-main --no-pager --all | |
systemctl is-failed deploy-main | grep -q "failed" && echo "Deployment Failed!" && exit 1 || exit 0 | |
- name: Update and Build Paradise Secondary | |
if: matrix.environment == 'Secondary' && inputs.perform_deploy_main | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.PRODUCTION_HOST }} | |
username: ${{ secrets.PRODUCTION_USERNAME }} | |
key: ${{ secrets.PRODUCTION_SSH_KEY }} | |
passphrase: ${{ secrets.PRODUCTION_SSH_KEY_PASS }} | |
script: | | |
systemctl is-failed deploy-main | grep -q "failed" && echo "Deployment Failed!" && exit 1 || exit 0 | |
- name: Update and Build Paradise Vega | |
if: matrix.environment == 'Vega' && inputs.perform_deploy_vega | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.PRODUCTION_HOST }} | |
username: ${{ secrets.PRODUCTION_USERNAME }} | |
key: ${{ secrets.PRODUCTION_SSH_KEY }} | |
passphrase: ${{ secrets.PRODUCTION_SSH_KEY_PASS }} | |
script: | | |
TIME=$(date +'%Y-%m-%d%T') | |
sudo systemctl --wait start deploy-vega | |
journalctl --since $TIME -u deploy-vega --no-pager --all | |
systemctl is-failed deploy-vega | grep -q "failed" && echo "Deployment Failed!" && exit 1 || exit 0 | |
- name: Update and Build Paradise Cleo | |
if: matrix.environment == 'Cleo' && inputs.perform_deploy_cleo | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.PRODUCTION_HOST }} | |
username: ${{ secrets.PRODUCTION_USERNAME }} | |
key: ${{ secrets.PRODUCTION_SSH_KEY }} | |
passphrase: ${{ secrets.PRODUCTION_SSH_KEY_PASS }} | |
script: | | |
TIME=$(date +'%Y-%m-%d%T') | |
sudo systemctl --wait start deploy-cleo | |
journalctl --since $TIME -u deploy-cleo --no-pager --all | |
systemctl is-failed deploy-cleo | grep -q "failed" && echo "Deployment Failed!" && exit 1 || exit 0 | |
- name: Update and Build Paradise Prime | |
if: matrix.environment == 'Prime' && inputs.perform_deploy_prime | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.PRODUCTION_HOST }} | |
username: ${{ secrets.PRODUCTION_USERNAME }} | |
key: ${{ secrets.PRODUCTION_SSH_KEY }} | |
passphrase: ${{ secrets.PRODUCTION_SSH_KEY_PASS }} | |
script: | | |
TIME=$(date +'%Y-%m-%d%T') | |
sudo systemctl --wait start deploy-prime | |
journalctl --since $TIME -u deploy-prime --no-pager --all | |
systemctl is-failed deploy-prime | grep -q "failed" && echo "Deployment Failed!" && exit 1 || exit 0 | |
- name: Update and Build Paradise WL | |
if: matrix.environment == 'WL' && inputs.perform_deploy_wl | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.PRODUCTION_HOST }} | |
username: ${{ secrets.PRODUCTION_USERNAME }} | |
key: ${{ secrets.PRODUCTION_SSH_KEY }} | |
passphrase: ${{ secrets.PRODUCTION_SSH_KEY_PASS }} | |
script: | | |
TIME=$(date +'%Y-%m-%d%T') | |
sudo systemctl --wait start deploy-wl | |
journalctl --since $TIME -u deploy-wl --no-pager --all | |
systemctl is-failed deploy-wl | grep -q "failed" && echo "Deployment Failed!" && exit 1 || exit 0 | |
- name: Update and Build Paradise Tutorial | |
if: matrix.environment == 'Tutorial' && inputs.perform_deploy_tutorial | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.PRODUCTION_HOST }} | |
username: ${{ secrets.PRODUCTION_USERNAME }} | |
key: ${{ secrets.PRODUCTION_SSH_KEY }} | |
passphrase: ${{ secrets.PRODUCTION_SSH_KEY_PASS }} | |
script: | | |
TIME=$(date +'%Y-%m-%d%T') | |
sudo systemctl --wait start deploy-tutorial | |
journalctl --since $TIME -u deploy-tutorial --no-pager --all | |
systemctl is-failed deploy-tutorial | grep -q "failed" && echo "Deployment Failed!" && exit 1 || exit 0 | |
- name: Update deployment status (success) | |
if: | | |
success() | |
uses: chrnorm/deployment-status@v2 | |
with: | |
token: '${{ github.token }}' | |
environment-url: ${{ steps.deployment.outputs.environment_url }} | |
log-url: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}' | |
deployment-id: ${{ steps.deployment.outputs.deployment_id }} | |
state: 'success' | |
- name: Update deployment status (failure) | |
if: | | |
failure() | |
uses: chrnorm/deployment-status@v2 | |
with: | |
token: '${{ github.token }}' | |
environment-url: ${{ steps.deployment.outputs.environment_url }} | |
log-url: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}' | |
deployment-id: ${{ steps.deployment.outputs.deployment_id }} | |
state: 'failure' | |
delete-automatic-deployments: | |
name: Delete Automatic Deployments | |
runs-on: ubuntu-latest | |
needs: [deploy] | |
if: always() | |
steps: | |
- name: Delete previous automatic deployments | |
uses: actions/github-script@v7 | |
env: | |
GITHUB_SHA_HEAD: ${{ github.sha }} | |
with: | |
script: | | |
const { GITHUB_SHA_HEAD } = process.env | |
const deployments = await github.rest.repos.listDeployments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
sha: GITHUB_SHA_HEAD | |
}); | |
await Promise.all( | |
deployments.data.filter((d) => d.performed_via_github_app).map(async (deployment) => { | |
await github.rest.repos.createDeploymentStatus({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
deployment_id: deployment.id, | |
state: 'inactive' | |
}); | |
return github.rest.repos.deleteDeployment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
deployment_id: deployment.id | |
}); | |
}) | |
); |