Skip to content

Commit

Permalink
ci: certification pipeline trigger (#256)
Browse files Browse the repository at this point in the history
* ci: certification pipeline trigger

* ci: split setRepository and updatePreviawble action
  • Loading branch information
ddeliziact authored Nov 8, 2024
1 parent bdbd9d0 commit 4019936
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 98 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/certify.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Request certification

on:
push:
tags:
# Release tags v1.0.0, v1.0.1, v1.0.2, etc.
- 'v[0-9]+.[0-9]+.[0-9]+'
# Pre-release tags v1.0.0-alpha.0, v1.0.0-beta.0, etc.
- 'v[0-9]+.[0-9]+.[0-9]+-[a-z]+.[0-9]+'
workflow_dispatch:

jobs:
certify:
name: Certify connector
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: '20.x'

- name: Certify
env:
CLIENT_ID: ${{ secrets.PUBLIC_CONNECTOR_CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.PUBLIC_CONNECTOR_CLIENT_SECRET }}
CONNECTOR_KEY: ${{ secrets.PUBLIC_CONNECTOR_CONNECTOR_KEY }}
PROJECT_KEY: ${{ secrets.PUBLIC_CONNECTOR_PROJECT_KEY }}
run: |
npm install -g @commercetools/cli
commercetools auth login --client-credentials --client-id $CLIENT_ID --client-secret $CLIENT_SECRET --project-key $PROJECT_KEY --region europe-west1.gcp
commercetools connect connectorstaged update --key $CONNECTOR_KEY --repository-tag $GITHUB_REF_NAME
commercetools connect connectorstaged certify --key $CONNECTOR_KEY
58 changes: 15 additions & 43 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,26 @@ name: CI
on: [push]

jobs:
build-enabler:
name: Build the application for enabler
validate:
name: Validate the applications
runs-on: ubuntu-latest
env:
CTP_REGION: ${{ secrets.CTP_REGION }}
defaults:
run:
working-directory: enabler
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Use Node.js 18.x
- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: '18.x'

- name: Install modules
run: npm ci

- name: Compile typescript
run: npm run build

- name: Execute tests
run: npm run test

build-processor:
name: Build the application for processor
runs-on: ubuntu-latest
env:
CTP_REGION: ${{ secrets.CTP_REGION }}
defaults:
run:
working-directory: processor
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Use Node.js 18.x
uses: actions/setup-node@v3
node-version: '20.x'

- name: Validate
run: |
npm install -g @commercetools/cli
commercetools connect validate --skip analysis
- name: Archive production artifacts
uses: actions/upload-artifact@v4
with:
node-version: '18.x'

- name: Install modules
run: npm ci

- name: Compile typescript
run: npm run build

- name: Execute tests
run: npm run test -- --coverage
name: validation-results
path: |
.connect
114 changes: 114 additions & 0 deletions .github/workflows/cko-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: Preview

on:
push:
tags:
# Release tags v1.0.0, v1.0.1, v1.0.2, etc.
- 'v[0-9]+.[0-9]+.[0-9]+'
# Pre-release tags v1.0.0-alpha.0, v1.0.0-beta.0, etc.
- 'v[0-9]+.[0-9]+.[0-9]+-[a-z]+.[0-9]+'
- latest
workflow_dispatch:

jobs:
publish:
name: Preview Connector
runs-on: ubuntu-latest
if: github.ref_type == 'tag'
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Setup Node.js 20
uses: actions/setup-node@v3
with:
node-version: 20

- name: Make previewable
env:
CLIENT_ID: ${{ secrets.CKO_CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.CKO_CLIENT_SECRET }}
CONNECTOR_KEY: ${{ secrets.CKO_CONNECTOR_KEY }}
run: |
TIMEOUT=600 # 10 minutes
START_TIME=$(date +%s)
echo "Updating connector to tag $GITHUB_REF_NAME"
echo "********************************"
echo Authenticating with commercetools
echo "********************************"
OAUTH_RESPONSE=$(curl --silent --show-error --location --request POST 'https://auth.europe-west1.gcp.commercetools.com/oauth/token?grant_type=client_credentials' -u $CLIENT_ID:$CLIENT_SECRET)
ACCESS_TOKEN=$(echo $OAUTH_RESPONSE | jq -r '.access_token')
echo Access token retrieved
echo "********************************"
echo Updating connector
echo "********************************"
CONNECTOR_DETAILS=$(curl --silent --show-error --location "https://connect.europe-west1.gcp.commercetools.com/connectors/drafts/key=$CONNECTOR_KEY" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $ACCESS_TOKEN")
VERSION=$(echo $CONNECTOR_DETAILS | jq -r '.version')
IS_PREVIWABLE=$(echo $CONNECTOR_DETAILS | jq -r '.isPreviewable')
echo "Updating connector version: $VERSION isPreviewable: $IS_PREVIWABLE"
CONNECTOR_DETAILS=$(curl --fail-with-body --silent --location POST "https://connect.europe-west1.gcp.commercetools.com/connectors/drafts/key=$CONNECTOR_KEY" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--data-raw "{\"version\": $VERSION, \"actions\": [{\"action\": \"setRepository\",\"url\": \"git@github.com:$GITHUB_REPOSITORY.git\",\"tag\": \"$GITHUB_REF_NAME\"}]}")
VERSION=$(echo $CONNECTOR_DETAILS | jq -r '.version')
CONNECTOR_DETAILS=$(curl --fail-with-body --silent --location POST "https://connect.europe-west1.gcp.commercetools.com/connectors/drafts/key=$CONNECTOR_KEY" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--data-raw "{\"version\": $VERSION, \"actions\": [{\"action\": \"updatePreviewable\"}]}")
# Validate when the `isPreviewable` is done
while true; do
# Calculate elapsed time
ELAPSED_TIME=$(($(date +%s) - START_TIME))
# Check if we've exceeded the timeout
if [ "$ELAPSED_TIME" -ge "$TIMEOUT" ]; then
echo "Timeout reached. Exiting with failure."
exit 1
fi
# Execute the curl request and capture the response
RESPONSE=$(curl --silent --show-error --location "https://connect.europe-west1.gcp.commercetools.com/connectors/drafts/key=$CONNECTOR_KEY" \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $ACCESS_TOKEN")
STATUS=$(echo "$RESPONSE" | jq -r '.isPreviewable')
CURRENT_VERSION=$(echo "$RESPONSE" | jq -r '.version')
# Check if the `isPreviewable` is still "pending"
if [ "$STATUS" != "pending" ]; then
# If it has changed, set it as an environment variable
export PREVIEW_STATUS="$STATUS"
export VERSION="$CURRENT_VERSION"
export PREVIEW_RESPONSE="$RESPONSE"
break
fi
# Optional: add a delay to avoid spamming the server with requests
echo "Connector isPreviewable is still $STATUS. Waiting 5 seconds..."
sleep 5
done
echo "isPreviewable has changed to: $PREVIEW_STATUS"
# Check if `PREVIEW_STATUS` is "true"
if [ "$PREVIEW_STATUS" != "true" ]; then
echo "Error: isPreviable is not 'true'. Exiting with failure."
echo $PREVIEW_RESPONSE
exit 1 # Exit with a non-zero status to indicate failure
fi
2 changes: 1 addition & 1 deletion .github/workflows/latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ jobs:
run: git tag -f -- "latest" && git push -f origin "latest"

- name: Trigger publish workflow
run: gh workflow run publish.yml --ref latest
run: gh workflow run cko-preview.yml --ref latest

53 changes: 0 additions & 53 deletions .github/workflows/publish.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Code Editor directories and files
.idea
.env
.env
.connect

0 comments on commit 4019936

Please sign in to comment.