mirror of
https://github.com/vercel/commerce.git
synced 2025-05-08 18:57:51 +00:00
chore: Update deployment workflow and status conditions in develop.deploy-functions.yml
This commit is contained in:
parent
6992a3ff19
commit
f60f6bdde2
76
.github/workflows/develop.deploy-functions.yml
vendored
76
.github/workflows/develop.deploy-functions.yml
vendored
@ -6,7 +6,22 @@ on:
|
|||||||
- develop
|
- develop
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
build-release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: 'actions/checkout@v4'
|
||||||
|
- name: Semantic Release
|
||||||
|
id: semantic
|
||||||
|
uses: cycjimmy/semantic-release-action@v4
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
|
||||||
|
|
||||||
deploy-to-gcp:
|
deploy-to-gcp:
|
||||||
|
needs: build-release
|
||||||
|
if: needs.build-release.outputs.new_release_published == 'true'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
environment: develop
|
environment: develop
|
||||||
permissions:
|
permissions:
|
||||||
@ -17,44 +32,11 @@ jobs:
|
|||||||
deployments: 'write'
|
deployments: 'write'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
|
||||||
uses: 'actions/checkout@v4'
|
|
||||||
- name: Delete Previous deployments
|
|
||||||
uses: actions/github-script@v6
|
|
||||||
with:
|
|
||||||
script: |
|
|
||||||
const deployments = await github.rest.repos.listDeployments({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
sha: context.sha
|
|
||||||
});
|
|
||||||
await Promise.all(
|
|
||||||
deployments.data.map(async (deployment) => {
|
|
||||||
# we can only delete inactive deployments, so let's deactivate them first
|
|
||||||
await github.rest.repos.createDeploymentStatus({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
deployment_id: deployment.id,
|
|
||||||
state: 'inactive'
|
|
||||||
});
|
|
||||||
return github.rest.repos.deleteDeployment({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
deployment_id: deployment.id
|
|
||||||
});
|
|
||||||
})
|
|
||||||
);
|
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: 'actions/checkout@v4'
|
uses: 'actions/checkout@v4'
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
- name: Semantic Release
|
|
||||||
id: semantic
|
|
||||||
uses: cycjimmy/semantic-release-action@v4
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
|
|
||||||
- name: Set Environment Variables
|
- name: Set Environment Variables
|
||||||
if: steps.semantic.outputs.new_release_published == 'true'
|
|
||||||
run: |
|
run: |
|
||||||
echo COMPANY_NAME="${{ env.COMPANY_NAME }}" > .env
|
echo COMPANY_NAME="${{ env.COMPANY_NAME }}" > .env
|
||||||
echo TWITTER_CREATOR="${{ env.TWITTER_CREATOR }}" >> .env
|
echo TWITTER_CREATOR="${{ env.TWITTER_CREATOR }}" >> .env
|
||||||
@ -63,53 +45,25 @@ jobs:
|
|||||||
echo SHOPIFY_REVALIDATION_SECRET="${{ env.SHOPIFY_REVALIDATION_SECRET }}" >> .env
|
echo SHOPIFY_REVALIDATION_SECRET="${{ env.SHOPIFY_REVALIDATION_SECRET }}" >> .env
|
||||||
echo SHOPIFY_STOREFRONT_ACCESS_TOKEN="${{ env.SHOPIFY_STOREFRONT_ACCESS_TOKEN }}" >> .env
|
echo SHOPIFY_STOREFRONT_ACCESS_TOKEN="${{ env.SHOPIFY_STOREFRONT_ACCESS_TOKEN }}" >> .env
|
||||||
echo SHOPIFY_STORE_DOMAIN="${{ env.SHOPIFY_STORE_DOMAIN }}" >> .env
|
echo SHOPIFY_STORE_DOMAIN="${{ env.SHOPIFY_STORE_DOMAIN }}" >> .env
|
||||||
- uses: chrnorm/deployment-action@v2
|
|
||||||
name: Create GitHub deployment
|
|
||||||
id: deployment
|
|
||||||
with:
|
|
||||||
token: '${{ secrets.GH_TOKEN}}'
|
|
||||||
environment-url: http://my-app-url.com
|
|
||||||
environment: develop
|
|
||||||
- name: Authenticate with Google Cloud
|
- name: Authenticate with Google Cloud
|
||||||
if: steps.semantic.outputs.new_release_published == 'true'
|
|
||||||
id: auth
|
id: auth
|
||||||
uses: google-github-actions/auth@v2
|
uses: google-github-actions/auth@v2
|
||||||
with:
|
with:
|
||||||
project_id: ${{ vars.PROJECT_ID }}
|
project_id: ${{ vars.PROJECT_ID }}
|
||||||
credentials_json: ${{secrets.CREDENTIALS_JSON}}
|
credentials_json: ${{secrets.CREDENTIALS_JSON}}
|
||||||
- name: Set up Cloud SDK
|
- name: Set up Cloud SDK
|
||||||
if: steps.semantic.outputs.new_release_published == 'true'
|
|
||||||
uses: 'google-github-actions/setup-gcloud@v2'
|
uses: 'google-github-actions/setup-gcloud@v2'
|
||||||
|
|
||||||
- name: Configure Docker
|
- name: Configure Docker
|
||||||
if: steps.semantic.outputs.new_release_published == 'true'
|
|
||||||
run: |
|
run: |
|
||||||
gcloud auth configure-docker
|
gcloud auth configure-docker
|
||||||
|
|
||||||
- name: Build and Push Docker Image
|
- name: Build and Push Docker Image
|
||||||
if: steps.semantic.outputs.new_release_published == 'true'
|
|
||||||
run: |
|
run: |
|
||||||
docker build -t gcr.io/${{ vars.PROJECT_ID }}/${{ vars.DOCKER_IMAGE_NAME }}:latest .
|
docker build -t gcr.io/${{ vars.PROJECT_ID }}/${{ vars.DOCKER_IMAGE_NAME }}:latest .
|
||||||
docker push gcr.io/${{ vars.PROJECT_ID}}/${{ vars.DOCKER_IMAGE_NAME }}:latest
|
docker push gcr.io/${{ vars.PROJECT_ID}}/${{ vars.DOCKER_IMAGE_NAME }}:latest
|
||||||
- id: 'deploy'
|
- id: 'deploy'
|
||||||
if: steps.semantic.outputs.new_release_published == 'true'
|
|
||||||
uses: 'google-github-actions/deploy-cloudrun@v2'
|
uses: 'google-github-actions/deploy-cloudrun@v2'
|
||||||
with:
|
with:
|
||||||
service: ${{vars.APP_NAME}}
|
service: ${{vars.APP_NAME}}
|
||||||
image: 'gcr.io/${{ vars.PROJECT_ID }}/${{ vars.DOCKER_IMAGE_NAME }}:latest'
|
image: 'gcr.io/${{ vars.PROJECT_ID }}/${{ vars.DOCKER_IMAGE_NAME }}:latest'
|
||||||
|
|
||||||
- name: Update deployment status (success)
|
|
||||||
if: success() && steps.semantic.outputs.new_release_published == 'true'
|
|
||||||
uses: chrnorm/deployment-status@v2
|
|
||||||
with:
|
|
||||||
token: '${{ secrets.GH_TOKEN }}'
|
|
||||||
environment-url: ${{steps.deploy.outputs.url}}
|
|
||||||
state: 'success'
|
|
||||||
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
|
|
||||||
- name: Update deployment status (failure)
|
|
||||||
if: failure() && steps.semantic.outputs.new_release_published == 'true'
|
|
||||||
uses: chrnorm/deployment-status@v2
|
|
||||||
with:
|
|
||||||
token: '${{ secrets.GH_TOKEN}}'
|
|
||||||
state: 'failure'
|
|
||||||
deployment-id: ${{ steps.deployment.outputs.deployment_id }}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user