From 12bf17e21e689248bf11d4ef603d17d3471e39f4 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 15 Jun 2023 19:37:18 +0100 Subject: [PATCH 1/2] Add workflow for deploying to staging --- .github/workflows/stage.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/stage.yml diff --git a/.github/workflows/stage.yml b/.github/workflows/stage.yml new file mode 100644 index 0000000000..caf2eaefd5 --- /dev/null +++ b/.github/workflows/stage.yml @@ -0,0 +1,32 @@ +name: "Deploy to Staging" + +on: + pull_request: + types: [labeled] + +permissions: + contents: read + +jobs: + deploy: + if: contains(fromJSON('["pr-staged-uk", "pr-staged-au", "pr-staged-fr"]'), github.event.label.name) + runs-on: ubuntu-latest + steps: + - name: Configure deployment key + run: | + install -m 600 -D /dev/null ~/.ssh/id_rsa + echo "${{ secrets.DEPLOYMENT_KEY }}" > ~/.ssh/id_rsa + echo "${{ secrets.DEPLOYMENT_HOSTS }}" > ~/.ssh/known_hosts + + - name: Deploy to Staging + env: + BRANCH_NAME: pull-request-${{ github.event.pull_request.number }} + LABEL: ${{ github.event.label.name }} + run: | + if [[ $LABEL == 'pr-staged-uk' ]]; then + ssh ofn-deploy@staging.openfoodnetwork.org.uk -o LogLevel=ERROR "$BRANCH_NAME" + elif [[ $LABEL == 'pr-staged-au' ]]; then + ssh ofn-deploy@staging.openfoodnetwork.org.au -o LogLevel=ERROR "$BRANCH_NAME" + elif [[ $LABEL == 'pr-staged-fr' ]]; then + ssh ofn-deploy@staging.coopcircuits.fr -o LogLevel=ERROR "$BRANCH_NAME" + fi From 584f6297f5d22b05f32e3764be9215d80132e6f4 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Thu, 15 Jun 2023 20:18:44 +0100 Subject: [PATCH 2/2] Allow manual workflow triggers --- .github/workflows/stage.yml | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/.github/workflows/stage.yml b/.github/workflows/stage.yml index caf2eaefd5..d5b53b5479 100644 --- a/.github/workflows/stage.yml +++ b/.github/workflows/stage.yml @@ -3,12 +3,22 @@ name: "Deploy to Staging" on: pull_request: types: [labeled] + workflow_dispatch: + inputs: + server: + description: "Staging Server" + type: choice + required: true + options: + - staging.openfoodnetwork.org.uk + - staging.openfoodnetwork.org.au + - staging.coopcircuits.fr permissions: contents: read jobs: - deploy: + deploy_pr: if: contains(fromJSON('["pr-staged-uk", "pr-staged-au", "pr-staged-fr"]'), github.event.label.name) runs-on: ubuntu-latest steps: @@ -30,3 +40,17 @@ jobs: elif [[ $LABEL == 'pr-staged-fr' ]]; then ssh ofn-deploy@staging.coopcircuits.fr -o LogLevel=ERROR "$BRANCH_NAME" fi + + deploy_branch: + if: ${{ inputs.server }} + runs-on: ubuntu-latest + steps: + - name: Configure deployment key + run: | + install -m 600 -D /dev/null ~/.ssh/id_rsa + echo "${{ secrets.DEPLOYMENT_KEY }}" > ~/.ssh/id_rsa + echo "${{ secrets.DEPLOYMENT_HOSTS }}" > ~/.ssh/known_hosts + + - name: Deploy to Staging + run: | + ssh ofn-deploy@${{ inputs.server }} -o LogLevel=ERROR "$GITHUB_REF"