Preview (build) #12813
This file contains hidden or 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: Preview (build) | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened, closed] | |
| paths-ignore: | |
| - 'microsite/**' | |
| - '*.md' | |
| jobs: | |
| build-backstage: | |
| env: | |
| NODE_OPTIONS: --max-old-space-size=4096 | |
| UFFIZZI_URL: https://uffizzi.com | |
| name: Build PR image | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event_name != 'pull_request' || github.event.action != 'closed' }} | |
| outputs: | |
| tags: ${{ steps.meta.outputs.tags }} | |
| steps: | |
| - name: checkout | |
| uses: actions/checkout@v3 | |
| - name: setup-node | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: 16.x | |
| registry-url: https://registry.npmjs.org/ | |
| - name: yarn install | |
| uses: backstage/actions/yarn-install@v0.6.4 | |
| with: | |
| cache-prefix: linux-v16 | |
| - name: Use Uffizzi's backstage app config | |
| run: | | |
| cp -f ./.github/uffizzi/uffizzi.production.app-config.yaml ./app-config.yaml | |
| - name: typescript build | |
| run: | | |
| yarn tsc | |
| - name: backstage build | |
| run: | | |
| yarn workspace example-backend build | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Generate UUID image name | |
| id: uuid | |
| run: echo "UUID_TAG_APP=$(uuidgen)" >> $GITHUB_ENV | |
| - name: Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v4 | |
| with: | |
| images: registry.uffizzi.com/${{ env.UUID_TAG_APP }} | |
| tags: type=raw,value=60d | |
| - name: Build Image | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: . | |
| file: packages/backend/Dockerfile | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| push: true | |
| render-compose-file: | |
| name: Render Docker Compose File | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build-backstage | |
| outputs: | |
| compose-file-cache-key: ${{ steps.hash.outputs.hash }} | |
| steps: | |
| - name: Checkout git repo | |
| uses: actions/checkout@v3 | |
| - name: Render Compose File | |
| run: | | |
| BACKSTAGE_IMAGE=$(echo ${{ needs.build-backstage.outputs.tags }}) | |
| export BACKSTAGE_IMAGE | |
| # Render simple template from environment variables. | |
| envsubst '$BACKSTAGE_IMAGE $GITHUB_SHA' < .github/uffizzi/docker-compose.uffizzi.yml > docker-compose.rendered.yml | |
| cat docker-compose.rendered.yml | |
| - name: Upload Rendered Compose File as Artifact | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: preview-spec | |
| path: docker-compose.rendered.yml | |
| retention-days: 2 | |
| - name: Upload PR Event as Artifact | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: preview-spec | |
| path: ${{ github.event_path }} | |
| retention-days: 2 | |
| delete-preview: | |
| name: Call for Preview Deletion | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.action == 'closed' }} | |
| steps: | |
| # If this PR is closing, we will not render a compose file nor pass it to the next workflow. | |
| - name: Upload PR Event as Artifact | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: preview-spec | |
| path: ${{ github.event_path }} | |
| retention-days: 2 |