From 941627b0bdcaa0f29ff626ebed56ce9de09155bb Mon Sep 17 00:00:00 2001 From: Noah Spannbauer Date: Sun, 23 Feb 2025 14:36:55 -0600 Subject: [PATCH] adding github workflows --- .github/workflows/api_build.yaml | 69 ++++++++++++++++++++++++++++ .github/workflows/app_build.yaml | 70 +++++++++++++++++++++++++++++ .github/workflows/changes.yaml | 28 ++++++++++++ .github/workflows/deploy.yaml | 35 +++++++++++++++ .github/workflows/main.yaml | 55 +++++++++++++++++++++++ .github/workflows/pull_request.yaml | 30 +++++++++++++ .github/workflows/tag.yaml | 44 ++++++++++++++++++ 7 files changed, 331 insertions(+) create mode 100644 .github/workflows/api_build.yaml create mode 100644 .github/workflows/app_build.yaml create mode 100644 .github/workflows/changes.yaml create mode 100644 .github/workflows/deploy.yaml create mode 100644 .github/workflows/main.yaml create mode 100644 .github/workflows/pull_request.yaml create mode 100644 .github/workflows/tag.yaml diff --git a/.github/workflows/api_build.yaml b/.github/workflows/api_build.yaml new file mode 100644 index 0000000..f76b078 --- /dev/null +++ b/.github/workflows/api_build.yaml @@ -0,0 +1,69 @@ +name: 'API Build' +on: + workflow_call: + inputs: + environment_name: + required: true + type: string + version_number: + required: true + type: string + +jobs: + build: + runs-on: ubuntu-latest + environment: ${{ inputs.environment_name }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + sparse-checkout: | + api + + - uses: pnpm/action-setup@v4 + name: Install pnpm + with: + version: 10 + run_install: false + + - name: Install Nest CLI + run: | + npm install -g @nestjs/cli + + - name: 'Setup Node' + uses: actions/setup-node@v4 + with: + node-version: ${{ vars.NODE_VERSION }} + + - name: Install dependencies + run: | + pnpm install + + - name: Build + run: | + pnpm --filter api build + + - name: Deploy + if: ${{ github.event_name != 'pull_request' }} + run: | + pnpm --filter api --prod deploy ./.prod/api + + - name: Log into Docker Hub + if: ${{ github.event_name != 'pull_request' }} + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Setup Docker Buildx + if: ${{ github.event_name != 'pull_request' }} + uses: docker/setup-buildx-action@v3 + + - name: Build and push to registry + if: ${{ github.event_name != 'pull_request' }} + uses: docker/build-push-action@v6 + with: + push: true + tags: noahspan/flying-api:${{ inputs.version_number }} + context: . + target: api diff --git a/.github/workflows/app_build.yaml b/.github/workflows/app_build.yaml new file mode 100644 index 0000000..5cc19da --- /dev/null +++ b/.github/workflows/app_build.yaml @@ -0,0 +1,70 @@ +name: 'App Build' +on: + workflow_call: + inputs: + environment_name: + required: true + type: string + version_number: + required: true + type: string + +env: + VITE_API_URL: ${{ vars.VITE_API_URL }} + VITE_CLIENT_ID: ${{ vars.VITE_CLIENT_ID }} + VITE_TENANT_ID: ${{ vars.VITE_TENANT_ID }} + VITE_REDIRECT_URL: ${{ vars.VITE_REDIRECT_URL }} + +jobs: + build: + runs-on: ubuntu-latest + environment: ${{ inputs.environment_name }} + steps: + - uses: actions/checkout@v4 + with: + sparse-checkout: | + app + + - uses: pnpm/action-setup@v4 + name: Install pnpm + with: + version: 10 + run_install: false + + - name: 'Setup Node' + uses: actions/setup-node@v4 + with: + node-version: ${{ vars.NODE_VERSION }} + + - name: Install + run: | + pnpm install + + - name: Build + run: | + pnpm --filter app build + + - name: Deploy + if: ${{ github.event_name != 'pull_request' }} + run: | + pnpm --filter app --prod deploy ./.prod/app + + - name: Setup Docker Buildx + if: ${{ github.event_name != 'pull_request' }} + uses: docker/setup-buildx-action@v3 + + - name: Log into Docker Hub + if: ${{ github.event_name != 'pull_request' }} + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push to registry + if: ${{ github.event_name != 'pull_request' }} + uses: docker/build-push-action@v6 + with: + push: true + tags: noahspan/flying-app:${{ inputs.version_number }} + context: . + target: app diff --git a/.github/workflows/changes.yaml b/.github/workflows/changes.yaml new file mode 100644 index 0000000..917786e --- /dev/null +++ b/.github/workflows/changes.yaml @@ -0,0 +1,28 @@ +name: Changes +on: + workflow_call: + outputs: + api: + value: ${{ jobs.changes.outputs.api }} + app: + value: ${{ jobs.changes.outputs.app }} + +jobs: + changes: + name: filter + runs-on: ubuntu-latest + outputs: + api: ${{ steps.filter.outputs.api }} + app: ${{ steps.filter.outputs.app }} + steps: + - uses: actions/checkout@v3 + + - uses: dorny/paths-filter@v3 + id: filter + with: + initial-fetch-depth: 2 + filters: | + api: + - 'api/**' + app: + - 'app/**' \ No newline at end of file diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..012e7c9 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,35 @@ +name: Deploy +on: + workflow_call: + inputs: + app_name: + required: true + type: string + environment_name: + required: true + type: string + version_number: + required: true + type: string + +permissions: + id-token: write + contents: read +jobs: + deploy: + runs-on: ubuntu-latest + environment: ${{ inputs.environment_name }} + steps: + - name: Log in to Azure + uses: azure/login@v2 + with: + client-id: ${{ vars.VITE_CLIENT_ID }} + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} + tenant-id: ${{ vars.VITE_TENANT_ID }} + + - name: Azure CLI script + uses: azure/cli@v2 + with: + azcliversion: latest + inlineScript: | + az containerapp update --name ${{ inputs.app_name }}-${{ inputs.environment_name }} --resource-group noahspan-flying --image docker.io/noahspan/${{ inputs.app_name }}:${{ inputs.version_number }} \ No newline at end of file diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..40a9e70 --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,55 @@ +name: Main +on: + push: + branches: + - main + +jobs: + changes: + uses: ./.github/workflows/changes.yaml + + build-api: + if: ${{ needs.changes.outputs.api == 'true' }} + name: build-api + needs: + - changes + uses: ./.github/workflows/api_build.yaml + with: + environment_name: test + version_number: ${{ github.run_id }} + secrets: inherit + + deploy-api: + name: deploy-api + needs: + - changes + - build-api + uses: ./.github/workflows/deploy.yaml + with: + app_name: flying-api + environment_name: test + version_number: ${{ github.run_id }} + secrets: inherit + + build-app: + if: ${{ needs.changes.outputs.app == 'true' }} + name: build-app + needs: + - changes + uses: ./.github/workflows/app_build.yaml + with: + environment_name: test + version_number: ${{ github.run_id }} + secrets: inherit + + deploy-app: + name: deploy-app + needs: + - changes + - build-app + uses: ./.github/workflows/deploy.yaml + with: + app_name: flying-app + environment_name: test + version_number: ${{ github.run_id }} + secrets: inherit diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml new file mode 100644 index 0000000..3de7e68 --- /dev/null +++ b/.github/workflows/pull_request.yaml @@ -0,0 +1,30 @@ +name: Pull Request + +on: + pull_request: + +jobs: + changes: + uses: ./.github/workflows/changes.yaml + + build-api: + if: ${{ needs.changes.outputs.api == 'true' }} + name: build-api + needs: + - changes + uses: ./.github/workflows/api_build.yaml + with: + environment_name: pull_request + version_number: ${{ github.run_id }} + secrets: inherit + + build-app: + if: ${{ needs.changes.outputs.app == 'true' }} + name: build-app + needs: + - changes + uses: ./.github/workflows/app_build.yaml + with: + environment_name: pull_request + version_number: ${{ github.run_id }} + secrets: inherit diff --git a/.github/workflows/tag.yaml b/.github/workflows/tag.yaml new file mode 100644 index 0000000..73277e2 --- /dev/null +++ b/.github/workflows/tag.yaml @@ -0,0 +1,44 @@ +name: Tag +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' + +jobs: + build-api: + name: build-api + uses: ./.github/workflows/api_build.yaml + with: + environment_name: prod + version_number: ${{ github.ref_name }} + secrets: inherit + + deploy-api: + name: deploy-api + needs: + - build-api + uses: ./.github/workflows/deploy.yaml + with: + app_name: flying-api + environment_name: prod + version_number: ${{ github.ref_name }} + secrets: inherit + + build-app: + name: build-app + uses: ./.github/workflows/app_build.yaml + with: + environment_name: prod + version_number: ${{ github.ref_name }} + secrets: inherit + + deploy-app: + name: deploy-app + needs: + - build-app + uses: ./.github/workflows/deploy.yaml + with: + app_name: flying-app + environment_name: prod + version_number: ${{ github.ref_name }} + secrets: inherit