From 8827106787faaceb7218be426a2d08bf3ee4818c Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 16 Dec 2021 10:01:03 +0100 Subject: [PATCH] Make build into reusable workflow --- .github/workflows/pull-request.yaml | 26 +++++++++++++ .../{build.yaml => template-build.yaml} | 39 +++++++------------ 2 files changed, 41 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/pull-request.yaml rename .github/workflows/{build.yaml => template-build.yaml} (75%) diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml new file mode 100644 index 00000000..b041e659 --- /dev/null +++ b/.github/workflows/pull-request.yaml @@ -0,0 +1,26 @@ +name: PullRequest + +on: + pull_request: {} + +jobs: + + build: + uses: appuio/cloud-portal/.github/workflows/template-build.yaml@preview-deployments + with: + namespace: appuio-cloud-preview + push_image: ${{ !contains(github.event.pull_request.labels.*.name, 'dependency') }} + + deploy: + # Don't deploy with Renovate PRs + if: ${{ !contains(github.event.pull_request.labels.*.name, 'dependency') }} + uses: appuio/cloud-portal/.github/workflows/template-deploy.yaml@preview-deployments + with: + namespace: appuio-cloud-preview + helm_release_name: portal-pr-${{ github.event.number }} + image_tag: pr-${{ github.event.number }} + revision: ${{ github.event.pull_request.head.sha }} + secrets: + openshift_token: ${{ secrets.OPENSHIFT_TOKEN }} + needs: + - build diff --git a/.github/workflows/build.yaml b/.github/workflows/template-build.yaml similarity index 75% rename from .github/workflows/build.yaml rename to .github/workflows/template-build.yaml index 4e5ec691..6840c1d0 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/template-build.yaml @@ -1,10 +1,13 @@ -name: Build - on: - push: - branches: - - master - pull_request: {} + workflow_call: + inputs: + namespace: + type: string + required: true + push_image: + type: boolean + required: false + default: false env: REGISTRY: registry.cloudscale-lpg-2.appuio.cloud @@ -33,7 +36,7 @@ jobs: - run: npm ci - run: npm run test - build: + dist: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -51,7 +54,7 @@ jobs: e2e: runs-on: ubuntu-latest needs: - - build + - dist steps: - uses: actions/checkout@v2 - uses: actions/download-artifact@v2 @@ -70,7 +73,7 @@ jobs: runs-on: ubuntu-latest environment: preview needs: - - build + - dist steps: - uses: actions/checkout@v2 - uses: actions/download-artifact@v2 @@ -83,9 +86,10 @@ jobs: uses: docker/metadata-action@v3 with: # by default, it creates the `:pr-#` tag in pull requests and branch name on `master` - images: ${{ env.REGISTRY }}/appuio-cloud-preview/${{ env.IMAGE_NAME }} + images: ${{ env.REGISTRY }}/${{ inputs.namespace }}/${{ env.IMAGE_NAME }} - name: Docker login + if: ${{ inputs.push_image }} uses: docker/login-action@v1 with: registry: ${{ env.REGISTRY }} @@ -96,19 +100,6 @@ jobs: uses: docker/build-push-action@v2 with: context: . - push: true + push: ${{ inputs.push_image }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - - deploy: - if: ${{ !contains(github.event.pull_request.labels.*.name, 'dependency') }} - uses: appuio/cloud-portal/.github/workflows/template-deploy.yaml@preview-deployments - with: - namespace: appuio-cloud-preview - helm_release_name: portal-pr-${{ github.event.number }} - image_tag: pr-${{ github.event.number }} - revision: ${{ github.event.pull_request.head.sha }} - secrets: - openshift_token: ${{ secrets.OPENSHIFT_TOKEN }} - needs: - - docker