Skip to content

fix(ci): use org-level variables for deploy host/user #9

fix(ci): use org-level variables for deploy host/user

fix(ci): use org-level variables for deploy host/user #9

Workflow file for this run

name: Build, push, and deploy combat-pubs-bot
on:
push:
branches: [master]
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: echotools/combat-pubs-bot
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=sha,prefix=sha-,format=short
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Deploy combat-pubs-bot
env:
SSH_HOST: ${{ vars.DEPLOY_HOST }}
SSH_USER: ${{ vars.DEPLOY_USER }}
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
run: |
mkdir -p ~/.ssh
echo "$DEPLOY_KEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -H "$SSH_HOST" >> ~/.ssh/known_hosts 2>/dev/null
ssh -o StrictHostKeyChecking=yes "$SSH_USER@$SSH_HOST" deploy-combat-pubs-bot
- name: Notify Discord
if: success()
env:
WEBHOOK_URL: ${{ secrets.DISCORD_DEPLOY_WEBHOOK }}
COMMIT_SHA: ${{ github.sha }}
GITHUB_REPOSITORY: ${{ github.repository }}
run: |
SHORT_SHA=$(echo "$COMMIT_SHA" | cut -c1-7)
PAYLOAD=$(jq -n \
--arg desc "combat-pubs-bot deployed and running\n[\`$SHORT_SHA\`](https://github.com/$GITHUB_REPOSITORY/commit/$COMMIT_SHA)" \
'{
embeds: [{
title: "combat-pubs-bot deployed",
description: $desc,
color: 5763719
}],
allowed_mentions: { parse: [] }
}')
curl -sf -H "Content-Type: application/json" -d "$PAYLOAD" "$WEBHOOK_URL"