Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions .github/workflows/publish.yml → .github/workflows/app-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ on:
push:
branches: [main]
paths-ignore:
- 'README.md'
- '**/*.md'
- '.gitignore'
- 'docker-compose.yml'
- '.github/workflows/ci.yml'
- '.github/workflows/app-ci.yml'
- '.github/workflows/uptime-check.yml'

env:
node_version: "22.x"
Expand Down Expand Up @@ -38,23 +38,44 @@ jobs:
working-directory: app
run: npm run build

# If you implement the Docker Publish step (see below), you can probably remove these next two steps
# These are just here to have a deploy-esque thing happen that doesn't require credentials
- name: Create deployment package
run: |
cd app
zip -r ../app-deployment.zip dist/ package.json package-lock.json
cd ..
echo "Created mock deployment package: app-deployment.zip"
- name: Upload deployment artifact
uses: actions/upload-artifact@v4
with:
name: app-deployment
path: app-deployment.zip
retention-days: 7

# Uncomment this step if you want to try uploading the app to Docker Hub
# However, you will need to set up a Docker Hub account and repository first
# TODO RE_COMMENT THESE LINES BELOW
build_and_deploy:
name: Push to Docker Hub
runs-on: ubuntu-latest
needs: [build]
steps:
- name: Check out
uses: actions/checkout@v4

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
# Add these secrets to your github repository if you want to try this step
# https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/use-secrets
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
# Change these two things if you want to try this step
# These are values for your Docker Hub Repo/Account, not GitHub
images: YOUR_ACCOUNT_HERE/YOUR_IMAGE_ID_HERE
- name: Build and push Docker image
uses: docker/build-push-action@v6
Expand Down
35 changes: 3 additions & 32 deletions .github/workflows/ci.yml → .github/workflows/app-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Continuous Integration
name: Merge Checks (CI)

on:
pull_request:
Expand All @@ -15,7 +15,7 @@ env:

jobs:
test:
name: Build & Test
name: Test
runs-on: ubuntu-latest
timeout-minutes: 3
steps:
Expand All @@ -32,40 +32,11 @@ jobs:
working-directory: app
run: npm ci --prefer-offline

- name: npm lint
working-directory: app
run: npm run lint

- name: npm run test
working-directory: app
run: npm run test

- name: npm run build
working-directory: app
run: npm run build

lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 3
steps:
- uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.node_version }}
cache: npm
cache-dependency-path: '**/package-lock.json'

- name: npm ci
working-directory: app
run: npm ci --prefer-offline

- name: npm lint
working-directory: app
run: npm run lint

# Make sure the Dockerfile builds properly as well, since we will likely deploy with Docker
docker:
name: Docker Build
runs-on: ubuntu-latest
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/uptime-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Uptime Check

on:
workflow_dispatch:
# schedule:
# - cron: '*/5 * * * *' # Every 5 minutes

jobs:
check:
name: Check Website Status
runs-on: ubuntu-latest
timeout-minutes: 5
env:
WEBSITE_URL: https://wikipedia.org
steps:
- name: Ping website
id: ping
run: |
if curl --fail --silent --head --max-time 10 ${{ env.WEBSITE_URL }} > /dev/null 2>&1; then
echo "status=up" >> $GITHUB_OUTPUT
echo "Website is up!"
else
echo "status=down" >> $GITHUB_OUTPUT
echo "Website is down!"
fi

# Uncomment this step if you have a discord webhook URL (add it to your repository secrets)
# for a channel that you want to send messages to. To see it actually send messages, I've inverted the condition
# so it actually notifies if the website is up, not down. In real use, we'd obviously want the opposite of that.
# TODO RE_COMMENT THESE LINES BELOW
- name: Send Discord notification
if: steps.ping.outputs.status == 'up'
# SWITCH TO THIS LINE FOR DOWNTIME DETECTION
# if: steps.ping.outputs.status == 'down'
run: |
curl -H "Content-Type: application/json" \
-d "{\"content\": \"**Website Alert**\n\nWebsite \`${{ env.WEBSITE_URL }}\` is currently **DOWN**.\n\nTime: $(date -u '+%Y-%m-%d %H:%M:%S UTC')\nWorkflow: ${{ github.workflow }}\nRun: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\"}" \
${{ secrets.DISCORD_WEBHOOK_URL }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# GitHub Actions Demo

> [!NOTE]
> See ./app/README.md for a more specific readme telling you how the code in this repo works
> See ./app/README.md for a more specific readme telling you how the code in this repo works. This document itself is more of an instruction manual for the skill-a-thon.

For an interactive experience, this repo is set up so that you can fork it to your personal GitHub accounts and practice pushing, opening pull-requests, and otherwise using the GitHub Action Workflows. I'll demonstrate how things work while I present. Maybe I'll also add in-depth explanations to the repo itself, if I have time.

Expand Down
2 changes: 0 additions & 2 deletions app/.gitignore

This file was deleted.

2 changes: 1 addition & 1 deletion app/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# A Website
This is a website. It uses a [Fastify](https://fastify.dev/) backend, running on [Node.js](https://nodejs.org/en), on the backend to serve raw HTML.

> [!NOTE]
> [!TIP]
> The BYU Office of IT and Lucid Software use Fastify in one way or another, alongside other big names like Mercedes. Industry leaders like the Linux Foundation recommend Fastify for Node.js web servers.

## Setup
Expand Down
2 changes: 1 addition & 1 deletion app/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
</head>
<body>
<h1>Hello World!</h1>
<p>I dare you to go to <a href="/rickroll">/rickroll</a></p>
<!-- I dare you to go to <a href="/rickroll">/rickroll</a> -->
</body>
</html>
6 changes: 0 additions & 6 deletions docker-compose.yml

This file was deleted.