-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci: create gh deployment entry as early as possible #1151
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,15 +8,62 @@ on: | |
- release/* | ||
|
||
jobs: | ||
create-deployment: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
environment-name: ${{ steps.determine-environment.outputs.name }} | ||
environment-code: ${{ steps.determine-environment.outputs.code }} | ||
deployment_id: ${{ steps.deployment.outputs.deployment_id }} | ||
steps: | ||
- name: Determine environment name | ||
id: determine-environment | ||
shell: bash | ||
run: | | ||
REF=${{ github.ref }} | ||
|
||
if [ $REF = 'refs/heads/main' ]; then | ||
ENVNAME='production' | ||
ENVCODE='demo-magento2' | ||
|
||
elif [ $REF = 'refs/heads/develop' ]; then | ||
ENVNAME='dev' | ||
ENVCODE='demo-magento2-dev' | ||
|
||
elif [[ $REF = refs/heads/release* ]]; then | ||
ENVNAME='canary' | ||
ENVCODE='demo-magento2-canary' | ||
|
||
elif [ $REF = 'refs/heads/enterprise' ]; then | ||
ENVNAME='enterprise' | ||
ENVCODE='demo-magento2-enterprise' | ||
|
||
else | ||
echo 'unrecognized branch name' | ||
exit 1 | ||
fi | ||
|
||
echo ::set-output name=name::$ENVNAME | ||
echo ::set-output name=code::$ENVCODE | ||
|
||
- name: Create GitHub deployment | ||
id: deployment | ||
uses: chrnorm/deployment-action@v2 | ||
with: | ||
token: ${{ secrets.DEPLOYMENT_PERSONAL_ACCESS_TOKEN }} | ||
environment: ${{ steps.determine-environment.outputs.name }} | ||
initial-status: in_progress | ||
build: | ||
needs: create-deployment | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v1 | ||
|
||
- name: Setup node | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 16.x | ||
|
||
- name: Build and publish docker image | ||
uses: elgohr/Publish-Docker-Github-Action@master | ||
with: | ||
|
@@ -65,54 +112,33 @@ jobs: | |
|
||
LAST_COMMIT: ${{ github.sha }} | ||
|
||
deploy-main: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for multiple deploys blocks now. They were only for assigning the correct environment name to a branch, but now this is handled by the bash script at the top of the file. |
||
deploy: | ||
needs: [create-deployment, build] | ||
uses: ./.github/workflows/deployment-template.yml | ||
needs: build | ||
if: github.ref == 'refs/heads/main' | ||
with: | ||
github_environment_name: production | ||
environment_code: demo-magento2 | ||
target_url: https://demo-magento2.europe-west1.gcp.storefrontcloud.io | ||
environment-code: ${{ needs.create-deployment.outputs.environment-code }} | ||
secrets: | ||
cloud_username: ${{ secrets.CLOUD_USERNAME }} | ||
cloud_password: ${{ secrets.CLOUD_PASSWORD }} | ||
deployment_status_token: ${{ secrets.DEPLOYMENT_PERSONAL_ACCESS_TOKEN }} | ||
cloud-username: ${{ secrets.CLOUD_USERNAME }} | ||
cloud-password: ${{ secrets.CLOUD_PASSWORD }} | ||
|
||
deploy-develop: | ||
uses: ./.github/workflows/deployment-template.yml | ||
needs: build | ||
if: github.ref == 'refs/heads/develop' | ||
with: | ||
github_environment_name: dev | ||
environment_code: demo-magento2-dev | ||
target_url: https://demo-magento2-dev.europe-west1.gcp.storefrontcloud.io | ||
secrets: | ||
cloud_username: ${{ secrets.CLOUD_USERNAME }} | ||
cloud_password: ${{ secrets.CLOUD_PASSWORD }} | ||
deployment_status_token: ${{ secrets.DEPLOYMENT_PERSONAL_ACCESS_TOKEN }} | ||
|
||
deploy-release: | ||
uses: ./.github/workflows/deployment-template.yml | ||
needs: build | ||
if: startsWith(github.ref, 'refs/heads/release') | ||
with: | ||
github_environment_name: canary | ||
environment_code: demo-magento2-canary | ||
target_url: https://demo-magento2-canary.europe-west1.gcp.storefrontcloud.io | ||
secrets: | ||
cloud_username: ${{ secrets.CLOUD_USERNAME }} | ||
cloud_password: ${{ secrets.CLOUD_PASSWORD }} | ||
deployment_status_token: ${{ secrets.DEPLOYMENT_PERSONAL_ACCESS_TOKEN }} | ||
finalize-deployment: | ||
runs-on: ubuntu-latest | ||
needs: [create-deployment, build, deploy] | ||
if: always() | ||
steps: | ||
- name: Update deployment status (success) | ||
if: ${{ !(contains(join(needs.*.result, ','), 'failure') || contains(join(needs.*.result, ','), 'cancelled')) }} | ||
uses: chrnorm/deployment-status@v2 | ||
with: | ||
token: ${{ secrets.DEPLOYMENT_PERSONAL_ACCESS_TOKEN }} | ||
deployment-id: ${{ needs.create-deployment.outputs.deployment_id }} | ||
state: success | ||
|
||
deploy-enterprise: | ||
uses: ./.github/workflows/deployment-template.yml | ||
needs: build | ||
if: github.ref == 'refs/heads/enterprise' | ||
with: | ||
github_environment_name: enterprise | ||
environment_code: demo-magento2-enterprise | ||
target_url: https://demo-magento2-enterprise.europe-west1.gcp.storefrontcloud.io | ||
secrets: | ||
cloud_username: ${{ secrets.CLOUD_USERNAME }} | ||
cloud_password: ${{ secrets.CLOUD_PASSWORD }} | ||
deployment_status_token: ${{ secrets.DEPLOYMENT_PERSONAL_ACCESS_TOKEN }} | ||
- name: Update deployment status (failure) | ||
if: ${{ contains(join(needs.*.result, ','), 'failure') || contains(join(needs.*.result, ','), 'cancelled') }} | ||
uses: chrnorm/deployment-status@v2 | ||
with: | ||
token: ${{ secrets.DEPLOYMENT_PERSONAL_ACCESS_TOKEN }} | ||
deployment-id: ${{ needs.create-deployment.outputs.deployment_id }} | ||
state: failure |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,42 +2,23 @@ | |
on: | ||
workflow_call: | ||
inputs: | ||
github_environment_name: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. deployment logic was moved out from this file. now it handles only the curl to vsf cloud |
||
environment-code: | ||
required: true | ||
type: string | ||
|
||
environment_code: | ||
required: true | ||
type: string | ||
|
||
target_url: | ||
required: true | ||
type: string | ||
secrets: | ||
cloud_username: | ||
cloud-username: | ||
required: true | ||
cloud_password: | ||
cloud-password: | ||
required: true | ||
deployment_status_token: # can be ${{ github.token }} | ||
required: true | ||
|
||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: chrnorm/deployment-action@releases/v1 | ||
name: Create GitHub deployment | ||
id: deployment | ||
with: | ||
token: ${{ secrets.deployment_status_token }} | ||
environment: ${{ inputs.github_environment_name }} | ||
initial_status: in_progress | ||
target_url: ${{ inputs.target_url }} | ||
- name: Deploy on ${{ inputs.target_url }} | ||
run: | | ||
if curl -s -H 'X-User-Id: ${{ secrets.cloud_username }}' -H 'X-Api-Key: ${{ secrets.cloud_password }}' -H 'Content-Type: application/json' -X POST -d '{ | ||
"code":"${{ inputs.environment_code }}", | ||
- run: | | ||
if curl -s -H 'X-User-Id: ${{ secrets.cloud-username }}' -H 'X-Api-Key: ${{ secrets.cloud-password }}' -H 'Content-Type: application/json' -X POST -d '{ | ||
"code":"${{ inputs.environment-code }}", | ||
"region":"europe-west1.gcp", | ||
"frontContainerVersion":"${{ github.sha }}" | ||
}' https://farmer.storefrontcloud.io/instances | grep -q '{"code":200,"result":"Instance updated!"}'; then | ||
|
@@ -46,24 +27,3 @@ jobs: | |
echo "Something went wrong during the update process..." | ||
exit 1 | ||
fi | ||
|
||
- name: Update deployment status (success) | ||
if: success() | ||
uses: chrnorm/deployment-status@releases/v1 | ||
with: | ||
token: ${{ secrets.deployment_status_token }} | ||
target_url: ${{ inputs.target_url }} | ||
state: success | ||
description: Congratulations! The deploy is done. | ||
deployment_id: ${{ steps.deployment.outputs.deployment_id }} | ||
|
||
- name: Update deployment status (failure) | ||
if: failure() | ||
uses: chrnorm/deployment-status@releases/v1 | ||
with: | ||
token: ${{ secrets.deployment_status_token }} | ||
target_url: ${{ inputs.target_url }} | ||
description: Unfortunately, the instance hasn't been updated. | ||
state: failure | ||
deployment_id: ${{ steps.deployment.outputs.deployment_id }} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated deployment-action and deployment-status to v2 from v1 - these are moslty naming convention changes and some alignments with gh api, so this should be a bit more up to date/easier to follow along with