Skip to content

Commit

Permalink
Merge pull request #2 from karola312/release-test
Browse files Browse the repository at this point in the history
Release test
  • Loading branch information
karola312 authored May 7, 2024
2 parents 405cb9b + c7ebcc5 commit a59cd2b
Show file tree
Hide file tree
Showing 11 changed files with 587 additions and 258 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-swans-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

release
77 changes: 77 additions & 0 deletions .github/actions/checks/create-pull-request-check/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Create-check
description: "Creates check for PR"
inputs:
PR_HEAD:
description: "Head of PR on which create check"
required: true
CHECK_NAME:
description: "Name of check"
required: true
STATUS:
description: "Status of check"
required: true
TITLE:
description: "Title of check"
required: true
DETAILS_URL:
description: "Details url"
required: true

outputs:
CHECK_ID:
description: "CHECK_ID"
value: ${{ steps.create-check.outputs.check_id }}

runs:
using: composite
steps:
- name: Get Pull Request head_sha
shell: bash
env:
GH_TOKEN: ${{ github.token }}
PR_HEAD: ${{ inputs.PR_HEAD }}
run: |
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/saleor/saleor-dashboard/pulls?head=saleor:${PR_HEAD}" > data.json
head_sha_with_quotes=$(jq '.[0] | .head.sha' data.json)
echo "PULL_REQUEST_HEAD_SHA=${head_sha_with_quotes//\"/}" >> "$GITHUB_ENV"
- name: Create check
if: ${{ env.PULL_REQUEST_HEAD_SHA }}
shell: bash
id: create-check
env:
GH_TOKEN: ${{ github.token }}
NAME: ${{ inputs.CHECK_NAME }}
STATUS: ${{ inputs.STATUS }}
TITLE: ${{ inputs.TITLE }}
run: |
payload=$(\
jq --null-input \
--arg name "$NAME" \
--arg head_sha "$PULL_REQUEST_HEAD_SHA" \
--arg status "$STATUS" \
--arg title "$TITLE" \
--arg details_url "$DETAILS_URL" \
'{
"name": $name,
"head_sha": $head_sha,
"status": $status,
"output": {
"title": $title,
"summary": "",
"text": "",
"details_url": $details_url
}
}'
)
check_id=$(curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/saleor/saleor-dashboard/check-runs \
-d "$payload" | jq -r '.id') ; echo "check_id=$check_id" >> "$GITHUB_OUTPUT"
69 changes: 69 additions & 0 deletions .github/actions/checks/update-pull-request-check/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Create-check
description: "Creates check for PR"
inputs:
CHECK_ID:
description: "Check id"
required: true
CHECK_NAME:
description: "Name of check - must be the same here and in create check"
required: true
STATUS:
description: "Status of check"
required: true
CONCLUSION:
description: "Conclusion of check, required if status completed"
required: false
TITLE:
description: "Title of check"
required: true
SUMMARY:
description: "Summary of check"
required: true
DETAILS_URL:
description: "Url with details to check"
required: true

runs:
using: composite
steps:
- name: Update check
shell: bash
env:
GH_TOKEN: ${{ github.token }}
CHECK_ID: ${{ inputs.CHECK_ID }}
NAME: ${{ inputs.CHECK_NAME }}
STATUS: ${{ inputs.STATUS }}
CONCLUSION: ${{inputs.CONCLUSION}}
TITLE: ${{ inputs.TITLE }}
SUMMARY: ${{ inputs.SUMMARY }}
DETAILS_URL: ${{ inputs.DETAILS_URL }}
run: |
payload=$(\
jq --null-input \
--arg name "$NAME" \
--arg status "$STATUS" \
--arg conclusion "$CONCLUSION" \
--arg title "$TITLE" \
--arg summary "$SUMMARY" \
--arg details_url "$DETAILS_URL" \
'{
"name": $name,
"status": $status,
"conclusion": $conclusion,
"output": {
"title": $title,
"summary": $summary,
"text": "",
"details_url": $details_url
}
}'
)
curl -L \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/saleor/saleor-dashboard/check-runs/$CHECK_ID" \
-d "$payload"
17 changes: 17 additions & 0 deletions .github/actions/prepare-api-variables/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ inputs:
MODE:
description: "The mode of running tests (pull-request, release, main)"
required: true
VERSION:
description: "Version if you want to run from different branch"
required: false

outputs:
BASE_URL:
Expand Down Expand Up @@ -36,6 +39,7 @@ runs:
MODE: ${{ inputs.MODE }}
PULL_REQUEST_NUMBER: ${{ github.event.number }}
PREFIX: pr-

run: |
if [[ "$MODE" == 'pull-request' ]]; then
echo "BASE_URL=https://${PREFIX}${PULL_REQUEST_NUMBER}.dashboard.saleor.rocks" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -73,6 +77,19 @@ runs:
exit 0
fi
if [[ "$MODE" == 'from-version' ]]; then
VERSION_SLUG=$(echo "${VERSION/./}")
echo "BASE_URL=https://v${VERSION_SLUG}.staging.saleor.cloud/dashboard/" >> "$GITHUB_OUTPUT"
echo "API_URL=https://v${VERSION_SLUG}.staging.saleor.cloud/graphql/" >> "$GITHUB_OUTPUT"
echo "BASE_URL_DOMAIN=v${VERSION_SLUG}.staging.saleor.cloud" >> "$GITHUB_OUTPUT"
echo "POOL_NAME=${VERSION} Staging" >> "$GITHUB_OUTPUT"
echo "POOL_INSTANCE=https://v${VERSION_SLUG}.staging.saleor.cloud/" >> "$GITHUB_OUTPUT"
echo "BACKUP_NAMESPACE=snapshot-automation-tests-${VERSION}" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Unknown mode: $MODE" >&2
exit 1
22 changes: 6 additions & 16 deletions .github/actions/prepare-tests-variables/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ inputs:
CLI_TOKEN:
description: "Saleor cli token"
required: true
VERSION:
description: "Version in format X.XX, if run from other branch"
required: false

outputs:
BASE_URL:
description: "Dashboard base url"
Expand Down Expand Up @@ -43,13 +47,7 @@ runs:
uses: ./.github/actions/prepare-api-variables
with:
MODE: ${{ inputs.MODE }}

- name: Generate backup
id: backup
uses: ./.github/actions/prepare-backups-variables
with:
CLI_TOKEN: ${{ inputs.CLI_TOKEN }}
BACKUP_NAMESPACE: ${{ steps.api.outputs.BACKUP_NAMESPACE }}
VERSION: ${{ inputs.VERSION || ''}}

- name: Print annotations
shell: bash
Expand All @@ -58,14 +56,6 @@ runs:
API_URL: ${{ steps.api.outputs.API_URL }}
POOL_NAME: ${{ steps.api.outputs.POOL_NAME }}
POOL_INSTANCE: ${{ steps.api.outputs.POOL_INSTANCE }}
BACKUP_ID: ${{ steps.backup.outputs.BACKUP_ID }}
BACKUP_VER: ${{ steps.backup.outputs.BACKUP_VER }}
BACKUP_NAME: ${{ steps.backup.outputs.BACKUP_NAME }}
BACKUP_NAMESPACE: ${{ steps.api.outputs.BACKUP_NAMESPACE }}
run: |
echo "::notice title=BASE_URL::${BASE_URL}"
echo "::notice title=API_URL::${API_URL}"
echo "::notice title=POOL_NAME::${POOL_NAME}"
echo "::notice title=POOL_INSTANCE::${POOL_INSTANCE}"
echo "::notice title=BACKUP_NAMESPACE::${BACKUP_NAMESPACE}"
echo "::notice title=SNAPSHOT::backup_id=${BACKUP_ID}, version=${BACKUP_VER}, name=${BACKUP_NAME}"
echo "::notice title=API_URL::${API_URL}"
130 changes: 130 additions & 0 deletions .github/workflows/deploy-staging-and-prepare-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: Deploy Dashboard to staging
on:
push:
branches:
# Matches release branches
- "[0-9]+.[0-9]+"

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
prepare-release:
name: Prepare release with Changesets
runs-on: ubuntu-22.04
outputs:
hasChangesets: ${{ steps.changesets.outputs.hasChangesets }}
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"
- name: Install Dependencies
run: npm ci
- name: Publishing version
uses: changesets/action@d89c1de63c7f28ac47ec85ed395f5f1d045d4697 # v1.4.4
id: changesets
with:
title: "Prepare release ${{ github.ref_name }}"
commit: "Release ${{ github.ref_name }}"
publish: "npm run release"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build:
needs: prepare-release
if: always()
runs-on: ubuntu-20.04
outputs:
MINOR_VERSION: ${{ env.MINOR_VERSION }}
CUSTOM_VERSION: ${{ env.CUSTOM_VERSION || env.VERSION }}
env:
API_URI: /graphql/
APP_MOUNT_URI: /dashboard/
STATIC_URL: /dashboard/static/
SENTRY_ORG: saleor
SENTRY_PROJECT: dashboard
SENTRY_URL_PREFIX: "~/dashboard/static"
APPS_MARKETPLACE_API_URI: "https://apps.staging.saleor.io/api/v2/saleor-apps"
VERSION: ${{ github.event.inputs.git_ref || github.ref_name }}
IS_CLOUD_INSTANCE: true
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.VERSION }}

- name: Set environment
# Convert version into staging deployment name (e.g 3.3.0 -> saleor-staging-v33)
run: |
set -x
environment=$(echo $VERSION | sed -n 's#\([0-9]\+\).\([0-9]\+\).*#saleor-staging-v\1\2#p')
echo "ENVIRONMENT=${environment}" >> "$GITHUB_ENV"
- name: Set custom version
env:
VERSION: ${{ github.event.inputs.git_ref || github.ref_name }}
# Add commit hash to basic version number
run: |
set -x
HASH=$(git rev-parse --short HEAD)
CURRENT_VERSION=$(jq -r .version package.json)
RELEASE="${CURRENT_VERSION}-${HASH}"
echo "CUSTOM_VERSION=${RELEASE}" >> "$GITHUB_ENV"
echo "SENTRY_RELEASE=${RELEASE}" >> "$GITHUB_ENV"
minor_version=$(echo "$VERSION" | sed -n 's#\([0-9]\+\).\([0-9]\+\).*#\1.\2#p')
echo "MINOR_VERSION=${minor_version}" >> "$GITHUB_ENV"
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version-file: ".nvmrc"

- name: Create check in prepare release PR
if: needs.prepare-release.outputs.hasChangesets == 'true'
id: create-check
uses: ./.github/actions/checks/create-pull-request-check
with:
PR_HEAD: "changeset-release/${{env.MINOR_VERSION}}"
CHECK_NAME: "Deploy_staging"
STATUS: "in_progress"
TITLE: "Deploy staging"
DETAILS_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"

- name: Package
timeout-minutes: 15
run: |
npm ci
- name: Build
run: |
npm run build
- name: Deploy
id: deploy
run: |
echo "Deploying..."
- name: Update check
if: always() && ${{ steps.create-check.outputs.CHECK_ID }}
uses: ./.github/actions/checks/update-pull-request-check
with:
CHECK_ID: ${{ steps.create-check.outputs.CHECK_ID }}
CHECK_NAME: "Deploy_staging"
STATUS: "${{ steps.deploy.outcome }}"
CONCLUSION: "${{ steps.deploy.conclusion }}"
TITLE: "Deploy staging"
SUMMARY: "Deploy finished with status ${{ steps.deploy.outcome }}. To check details: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
DETAILS_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"

run-tests-on-release:
needs: [prepare-release, build]
if: needs.prepare-release.outputs.hasChangesets == 'true'
uses: ./.github/workflows/run-tests-on-release.yml
with:
VERSION: ${{ needs.build.MINOR_VERSION }} # eg. "3.19"
CUSTOM_VERSION: ${{ needs.build.CUSTOM_VERSION }} # eg. "3.19.4-5a41d18"
secrets: inherit
Loading

0 comments on commit a59cd2b

Please sign in to comment.