v0 #26
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: CI Workflow | |
on: | |
pull_request: | |
branches: | |
- "**" | |
push: | |
branches: | |
- dev | |
- main | |
jobs: | |
linting-and-formatting: | |
name: Perform linting and formatting checks | |
runs-on: ubuntu-latest | |
outputs: | |
short_commit_hash: ${{ steps.get_commit_hash.outputs.short_commit_hash }} | |
steps: | |
- name: Checkout the Repository | |
uses: actions/checkout@v3 | |
- name: Install Dependencies | |
run: npm install | |
- name: Run linting check | |
run: npm run lint:check | |
- name: Check formatting | |
run: npm run format:check | |
- name: Get Short Commit Hash | |
id: get_commit_hash | |
run: echo "short_commit_hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
build-application: | |
name: Build Application | |
runs-on: ubuntu-latest | |
needs: linting-and-formatting | |
if: github.event_name == 'push' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.REPO_TOKEN }} | |
- name: Build and Push app.prod Image | |
run: | | |
REPO_NAME_LOWER=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]') | |
docker build -f Dockerfile.app.prod -t ghcr.io/$REPO_NAME_LOWER/app-prod:${{ needs.linting-and-formatting.outputs.short_commit_hash }} . | |
docker push ghcr.io/$REPO_NAME_LOWER/app-prod:${{ needs.linting-and-formatting.outputs.short_commit_hash }} | |
- name: Build and Push hls_proxy Image | |
run: | | |
REPO_NAME_LOWER=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]') | |
docker build -f Dockerfile.hls_proxy.prod -t ghcr.io/$REPO_NAME_LOWER/hls-proxy:${{ needs.linting-and-formatting.outputs.short_commit_hash }} . | |
docker push ghcr.io/$REPO_NAME_LOWER/hls-proxy:${{ needs.linting-and-formatting.outputs.short_commit_hash }} | |
update-infra: | |
name: Update the infra with new Docker images | |
runs-on: ubuntu-latest | |
needs: [linting-and-formatting, build-application] | |
if: github.event_name == 'push' | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
path: main | |
- name: Checkout Infra Repository | |
uses: actions/checkout@v4 | |
with: | |
repository: ${{ github.actor }}/aniweeb_infra | |
token: ${{ secrets.INFRA_REPO_PAT }} | |
path: infra-repo | |
- name: Update Deployment Manifests | |
run: | | |
cd infra-repo | |
REPO_NAME_LOWER=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]') | |
# Update app deployment | |
sed -i "s|image: ghcr.io/.*/app-prod:.*|image: ghcr.io/$REPO_NAME_LOWER/app-prod:${{ needs.linting-and-formatting.outputs.short_commit_hash }}|g" k8s/app/deployment.yaml | |
# Update hls-proxy deployment | |
sed -i "s|image: ghcr.io/.*/hls-proxy:.*|image: ghcr.io/$REPO_NAME_LOWER/hls-proxy:${{ needs.linting-and-formatting.outputs.short_commit_hash }}|g" k8s/hls-proxy/deployment.yaml | |
- name: Configure Git | |
run: | | |
cd infra-repo | |
git config user.name "${{ github.actor }}" | |
git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com" | |
- name: Commit and Push Changes | |
run: | | |
cd infra-repo | |
git add k8s/app/deployment.yaml k8s/hls-proxy/deployment.yaml | |
git commit -m "Update deployment images to ${{ needs.linting-and-formatting.outputs.short_commit_hash }}" | |
git push |