From 9bdf761d1fcaa199acd0cea814a7d433ade89455 Mon Sep 17 00:00:00 2001 From: Sam Gammon Date: Thu, 17 Nov 2022 16:56:30 -0800 Subject: [PATCH] Feature: Deploys Adds a sub-workflow which can be dispatched generically to deploy an Elide sample or app. Changes enclosed: - Add deployment sub-workflow - Use it from regular build --- .github/workflows/build.ci.yml | 49 ++++++++---------- .github/workflows/deploy.ci.yml | 92 +++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/deploy.ci.yml diff --git a/.github/workflows/build.ci.yml b/.github/workflows/build.ci.yml index 211cb86f9b..790677d779 100644 --- a/.github/workflows/build.ci.yml +++ b/.github/workflows/build.ci.yml @@ -39,6 +39,7 @@ jobs: license-check: true vulnerability-check: true fail-on-severity: "low" + base-ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || 'v3' }} - name: "Patch: Restore Yarn Lock" run: mv kotlin-js-store/yarn.inert kotlin-js-store/yarn.lock @@ -285,6 +286,7 @@ jobs: if: | ( github.ref == 'refs/heads/stable' || + github.ref == 'refs/heads/v3' || contains(github.event.pull_request.labels.*.name, 'ci:test-native') || contains(github.event.head_commit.message, 'ci:test-native') || startsWith(github.ref, 'refs/tags/v') @@ -370,6 +372,7 @@ jobs: if: | ( github.ref == 'refs/heads/stable' || + github.ref == 'refs/heads/v3' || contains(github.event.pull_request.labels.*.name, 'ci:build-img-jvm') || contains(github.event.head_commit.message, 'ci:build-img-jvm') || startsWith(github.ref, 'refs/tags/v') @@ -470,6 +473,7 @@ jobs: if: | ( github.ref == 'refs/heads/stable' || + github.ref == 'refs/heads/v3' || contains(github.event.pull_request.labels.*.name, 'ci:build-img-native') || contains(github.event.head_commit.message, 'ci:build-img-native') || startsWith(github.ref, 'refs/tags/v') @@ -563,46 +567,35 @@ jobs: ## deploy-samples: - strategy: - matrix: - category: [fullstack] - app: [react-ssr] - variant: [jvm] - name: "Deploy" - runs-on: ubuntu-latest needs: [gradle, tests-jvm, tests-native, docker-jvm, docker-native] if: | ( github.ref == 'refs/heads/stable' || + github.ref == 'refs/heads/v3' || contains(github.event.pull_request.labels.*.name, 'ci:deploy-samples') || contains(github.event.head_commit.message, 'ci:deploy-samples') || startsWith(github.ref, 'refs/tags/v') ) + strategy: + matrix: + category: [fullstack] + app: [react-ssr] + variant: [jvm] + permissions: contents: "read" id-token: "write" checks: "write" pull-requests: "write" - - steps: - ## Setup: Checkout Code - - name: "Setup: Checkout" - uses: actions/checkout@v3 - - ## Setup: Fly - - name: "Setup: Fly" - uses: superfly/flyctl-actions/setup-flyctl@master - - - name: "Deploy: ${{ matrix.sample }} (${{ matrix.variant }})" - env: - FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} - SAMPLE_CATEGORY: ${{ matrix.category }} - SAMPLE_APP: ${{ matrix.app }} - SAMPLE_VARIANT: ${{ matrix.variant }} - run: | - cd samples/$SAMPLE_CATEGORY/$SAMPLE_APP && \ - flyctl deploy \ - --remote-only \ - --image "us-docker.pkg.dev/elide-fw/samples/$SAMPLE_CATEGORY/$SAMPLE_APP/$SAMPLE_VARIANT:opt-latest"; + deployments: "write" + statuses: "write" + + uses: elide-dev/v3/.github/workflows/deploy.ci.yml@v3-deploys + secrets: inherit + with: + path: "samples/${{ matrix.category }}/${{ matrix.app }}" + image: "us-docker.pkg.dev/elide-fw/samples/$SAMPLE_CATEGORY/$SAMPLE_APP/$SAMPLE_VARIANT:opt-latest" + environment: samples + url: https://${{ matrix.app }}.samples.elide.dev diff --git a/.github/workflows/deploy.ci.yml b/.github/workflows/deploy.ci.yml new file mode 100644 index 0000000000..4dbef00498 --- /dev/null +++ b/.github/workflows/deploy.ci.yml @@ -0,0 +1,92 @@ +name: Deployment + +concurrency: + group: "deploy" + cancel-in-progress: false + +on: + ## Deployment can be invoked from other workflows. + workflow_call: + inputs: + ## Path to the app to deploy. + path: + description: "Path" + required: true + default: "samples/fullstack/react-ssr" + type: string + + ## Environment to update with this deployment. + environment: + description: "Target" + type: string + required: true + + ## URL target for this deployment. + url: + description: "URL" + type: string + required: true + + ## Optional image tag to deploy. If not specified, the "latest" image will be deployed. + image: + description: "Image" + type: string + required: false + + secrets: + FLY_API_TOKEN: + required: true + + ## Deployment can be triggered manually. + workflow_dispatch: + inputs: + path: + description: "Site" + required: true + default: "samples/fullstack/react-ssr" + type: choice + options: + - samples/fullstack/react-ssr + environment: + description: "Target" + type: environment + required: true + url: + description: "URL" + type: string + required: true + image: + description: "Image" + type: string + required: false + +jobs: + deployment: + name: "Deploy (${{ inputs.environment }})" + runs-on: "ubuntu-latest" + environment: ${{ inputs.environment }} + concurrency: "deploy-${{ inputs.environment }}" + permissions: + contents: "read" + id-token: "write" + checks: "write" + pull-requests: "write" + statuses: "write" + deployments: "write" + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} + steps: + ## Setup: Checkout Code + - name: "Setup: Checkout" + uses: actions/checkout@v3 + + ## Setup: Fly + - name: "Setup: Fly" + uses: superfly/flyctl-actions/setup-flyctl@master + + ## Deploy: App + - name: "Deploy: Fly (${{ inputs.environment }})" + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} + run: | + cd ${{ inputs.path }} && flyctl deploy --remote-only ${{ inputs.image != '' && format('--image {0}', inputs.image) || '' }};