Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Merge pull request #17 from 0d9e-tech/amogus #278

Merge pull request #17 from 0d9e-tech/amogus

Merge pull request #17 from 0d9e-tech/amogus #278

Workflow file for this run

name: Build
on:
push:
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Fetch main branch
run: git fetch origin amogus:amogus
continue-on-error: true
- name: Setup Deno
uses: denoland/setup-deno@v2
- name: Run Deno lint
run: deno check && deno lint
id: lint
continue-on-error: true
- name: Set check status
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "${{ steps.lint.outcome }}" == "success" ]; then
conclusion="success"
else
conclusion="failure"
fi
gh api --method POST /repos/${{ github.repository }}/check-runs \
-f name="Deno Lint" \
-f head_sha="${{ github.sha }}" \
-f status="completed" \
-f conclusion="$conclusion" \
-f output.title="Deno Lint Results" \
-f output.summary="Deno lint completed with $conclusion."
# if ok: build and deploy
- name: Setup Docker Buildx
if: ${{ steps.lint.outcome == 'success' }}
uses: docker/setup-buildx-action@v2
- name: Login to ghcr.io
if: ${{ steps.lint.outcome == 'success' }}
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
if: ${{ (github.ref == 'refs/heads/amogus' || github.ref == 'refs/heads/sus') && steps.lint.outcome == 'success' }}
uses: docker/build-push-action@v3
with:
push: true
tags: ghcr.io/0d9e-tech/web:${{ github.ref == 'refs/heads/amogus' && 'staging' || 'latest' }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Deploy
if: ${{ (github.ref == 'refs/heads/amogus' || github.ref == 'refs/heads/sus') && steps.lint.outcome == 'success' }}
run: |
curl --fail-with-body --no-progress-meter -i https://0d9e.tech/deploy -X POST \
-H "x-token: ${{ github.ref == 'refs/heads/amogus' && secrets.STAGING_TOKEN || secrets.DEPLOY_TOKEN }}"
- name: Comment
if: ${{ github.ref == 'refs/heads/amogus' && steps.lint.outcome == 'success' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
num=$(gh pr list -B sus -H amogus --json number | jq .[0].number -r)
if [ "$num" = "null" ]; then
gh pr create --base sus --head amogus --title "Release to sus" --body ""
num=$(gh pr list -B sus -H amogus --json number | jq .[0].number -r)
fi
gh pr comment $num --body "@${{ github.actor }} Your changes were deployed to staging, you can merge them here."
# else: revert the commit(s)
- name: Revert commit(s)
if: ${{ steps.lint.outcome != 'success' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
before=${{ github.event.before }}
if [ "$before" = "0000000000000000000000000000000000000000" ]; then
before=$(git merge-base amogus HEAD)
fi
gh api \
--method POST \
/repos/${{ github.repository }}/commits/${{ github.sha }}/comments \
-f 'body=Bruh, learn to code'
git reset --hard $before
git push origin HEAD:${{ github.ref }} --force