Skip to content

Commit

Permalink
Add modular workflows and reusable jobs for CI/CD processes
Browse files Browse the repository at this point in the history
* **Documentation**: Update `docs/architecture/workflows.md` to describe new modular workflows and reusable jobs.
* **Workflows**: Add new workflows for checking no org, creating feature test package, creating test scratch org, configuring org for testing, running tests, disposing of org, and creating org.
  - `.github/workflows/check-no-org.yml`
  - `.github/workflows/create-feature-test-package.yml`
  - `.github/workflows/create-test-scratch-org.yml`
  - `.github/workflows/configure-org-for-testing.yml`
  - `.github/workflows/run-tests.yml`
  - `.github/workflows/dispose-org.yml`
  - `.github/workflows/create-org.yml`
  • Loading branch information
jlantz committed Nov 1, 2024
1 parent cebc4a0 commit 7fb7f49
Show file tree
Hide file tree
Showing 8 changed files with 601 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/check-no-org.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Check No Org

on:
workflow_call:
inputs:
debug:
description: "Enable debug logging output for CumulusCI"
required: false
default: false
type: boolean
secrets:
github-token:
required: true

jobs:
check-no-org:
name: "Check No Org"
runs-on: ubuntu-latest
container:
image: ghcr.io/muselab-d2x/d2x:cumulusci-next-snapshots
options: --user root
credentials:
username: "${{ github.actor }}"
password: "${{ secrets.github-token }}"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run Checks
run: |
set -e {
cci task run check_no_org \
$([[ "${{ inputs.debug }}" == "true" ]] && echo " --debug")
} || {
echo "::error::Failed to run checks. Running cci error info..."
cci error info
exit 1
}
shell: bash
73 changes: 73 additions & 0 deletions .github/workflows/configure-org-for-testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Configure Org for Testing

on:
workflow_call:
inputs:
org:
required: false
default: feature
type: string
debug:
required: false
default: false
type: boolean
secrets:
dev-hub-auth-url:
required: false
dev-hub-username:
required: false
dev-hub-client-id:
required: false
dev-hub-private-key:
required: false
gh-email:
required: true
github-token:
required: true
github-app-id:
required: false
github-app-key:
required: false

jobs:
configure-org-for-testing:
name: "Configure Org for Testing"
runs-on: ubuntu-latest
container:
image: ghcr.io/muselab-d2x/d2x:cumulusci-next-snapshots
options: --user root
credentials:
username: "${{ github.actor }}"
password: "${{ secrets.github-token }}"
steps:
- name: D2X Image Details
run: |
echo "D2X Docker Image: ghcr.io/muselab-d2x/d2x"
echo "D2X Docker Tag: cumulusci-next-snapshots"
echo "D2X Docker Image: ghcr.io/muselab-d2x/d2x:cumulusci-next-snapshots" >> $GITHUB_STEP_SUMMARY
shell: bash

- name: Checkout
uses: actions/checkout@v4

- name: Auth to DevHub
run: /usr/local/bin/devhub.sh
env:
DEV_HUB_AUTH_URL: "${{ secrets.dev-hub-auth-url }}"
DEV_HUB_USERNAME: "${{ secrets.dev-hub-username }}"
DEV_HUB_CLIENT_ID: "${{ secrets.dev-hub-client-id }}"
DEV_HUB_PRIVATE_KEY: "${{ secrets.dev-hub-private-key }}"

- name: Set ${{ inputs.org }} org as default org
run: cci org default ${{ inputs.org }}

- name: Configure Org for Testing
id: configure_org
env:
GITHUB_TOKEN: "${{ secrets.github-token }}"
CUMULUSCI_SERVICE_github: '{ "username": "${{ github.actor }}", "token": "${{ secrets.github-token }}", "email": "${{ secrets.gh-email }}" }'
GITHUB_APP_ID: "${{ secrets.github-app-id }}"
GITHUB_APP_KEY: "${{ secrets.github-app-key }}"
run: |
cci flow run ci_feature_2gp --skip-from run-tests
shell: bash
88 changes: 88 additions & 0 deletions .github/workflows/create-feature-test-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Create Feature Test Package

on:
workflow_call:
inputs:
org:
required: false
default: feature
type: string
debug:
required: false
default: false
type: boolean
docker_image:
required: false
default: ghcr.io/muselab-d2x/d2x
type: string
docker_tag:
type: string
required: false
default: cumulusci-next-snapshots
secrets:
dev-hub-auth-url:
required: false
dev-hub-username:
required: false
dev-hub-client-id:
required: false
dev-hub-private-key:
required: false
gh-email:
required: true
github-token:
required: true
github-app-id:
required: false
github-app-key:
required: false

jobs:
create-feature-test-package:
name: "Create Feature Test Package"
runs-on: ubuntu-latest
container:
image: ${{ inputs.docker_image }}:${{ inputs.docker_tag }}
options: --user root
credentials:
username: "${{ github.actor }}"
password: "${{ secrets.github-token }}"
steps:
- name: D2X Image Details
run: |
echo "D2X Docker Image: ${{ inputs.docker_image }}"
echo "D2X Docker Tag: ${{ inputs.docker_tag }}"
echo "D2X Docker Image: `${{ inputs.docker_image }}:${{ inputs.docker_tag }}`" >> $GITHUB_STEP_SUMMARY
shell: bash
- name: Checkout
uses: actions/checkout@v4
- name: Auth to DevHub
run: /usr/local/bin/devhub.sh
env:
DEV_HUB_AUTH_URL: "${{ secrets.dev-hub-auth-url }}"
DEV_HUB_USERNAME: "${{ secrets.dev-hub-username }}"
DEV_HUB_CLIENT_ID: "${{ secrets.dev-hub-client-id }}"
DEV_HUB_PRIVATE_KEY: "${{ secrets.dev-hub-private-key }}"
- name: Set ${{ inputs.org }} org as default org
run: cci org default ${{ inputs.org }}
- name: Build Feature Test Package
env:
GITHUB_TOKEN: "${{ secrets.github-token }}"
CUMULUSCI_SERVICE_github: '{ "username": "${{ github.actor }}", "token": "${{ secrets.github-token }}", "email": "${{ secrets.gh-email }}" }'
GITHUB_APP_ID: "${{ secrets.github-app-id }}"
GITHUB_APP_KEY: "${{ secrets.github-app-key }}"
run: cci flow run build_feature_test_package $([[ "${{ inputs.debug }}" == "true" ]] && echo " --debug") | tee cumulusci-flow.log
shell: bash
- name: Set Commit Status
env:
GITHUB_TOKEN: "${{ secrets.github-token }}"
run: |
VERSION=$(cat cumulusci-flow.log | grep -o -E -m 1 "04t[a-zA-Z0-9]{15}")
gh api \
--method POST \
-H "Accept: application/vnd.github.v3+json" \
'/repos/${{ github.repository }}/statuses/${{ github.sha }}' \
-f state='success' \
-f description="version_id: $VERSION" \
-f context='Build Feature Test Package'
shell: bash
76 changes: 76 additions & 0 deletions .github/workflows/create-org.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Create Org

on:
workflow_call:
inputs:
scratchdef_path:
description: "Path to the scratch definition file"
required: false
type: string
cli_options:
description: "CLI options for creating the scratch org"
required: false
type: string
scratch_profile_name:
description: "CumulusCI scratch profile name"
required: false
default: feature
type: string
scratchdef_json:
description: "Scratch definition as JSON"
required: false
type: string
secrets:
dev-hub-auth-url:
required: true
dev-hub-username:
required: true
dev-hub-client-id:
required: true
dev-hub-private-key:
required: true
gh-email:
required: true
github-token:
required: true

jobs:
create-org:
name: "Create Org"
runs-on: ubuntu-latest
container:
image: ghcr.io/muselab-d2x/d2x:cumulusci-next-snapshots
options: --user root
credentials:
username: "${{ github.actor }}"
password: "${{ secrets.github-token }}"
env:
DEV_HUB_AUTH_URL: "${{ secrets.dev-hub-auth-url }}"
DEV_HUB_USERNAME: "${{ secrets.dev-hub-username }}"
DEV_HUB_CLIENT_ID: "${{ secrets.dev-hub-client-id }}"
DEV_HUB_PRIVATE_KEY: "${{ secrets.dev-hub-private-key }}"
CUMULUSCI_SERVICE_github: '{ "username": "${{ github.actor }}", "token": "${{ secrets.github-token }}", "email": "${{ secrets.gh-email }}" }'
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Auth to DevHub
run: /usr/local/bin/devhub.sh

- name: Create Scratch Org
run: |
if [ -n "${{ inputs.scratchdef_path }}" ]; then
cci org scratch ${{ inputs.scratch_profile_name }} -f ${{ inputs.scratchdef_path }} ${{ inputs.cli_options }}
elif [ -n "${{ inputs.scratchdef_json }}" ]; then
echo "${{ inputs.scratchdef_json }}" > scratchdef.json
cci org scratch ${{ inputs.scratch_profile_name }} -f scratchdef.json ${{ inputs.cli_options }}
else
cci org scratch ${{ inputs.scratch_profile_name }} ${{ inputs.cli_options }}
fi
- name: Create Access Token Session Environment
run: |
ACCESS_TOKEN=$(cci org info ${{ inputs.scratch_profile_name }} --json | jq -r '.access_token')
INSTANCE_URL=$(cci org info ${{ inputs.scratch_profile_name }} --json | jq -r '.instance_url')
echo "ACCESS_TOKEN=${ACCESS_TOKEN}" >> $GITHUB_ENV
echo "INSTANCE_URL=${INSTANCE_URL}" >> $GITHUB_ENV
76 changes: 76 additions & 0 deletions .github/workflows/create-test-scratch-org.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Create Test Scratch Org

on:
workflow_call:
inputs:
scratchdef_path:
description: "Path to the scratch definition file"
required: false
type: string
cli_options:
description: "CLI options for creating the scratch org"
required: false
type: string
scratch_profile_name:
description: "CumulusCI scratch profile name"
required: false
default: feature
type: string
scratchdef_json:
description: "Scratch definition as JSON"
required: false
type: string
secrets:
dev-hub-auth-url:
required: true
dev-hub-username:
required: true
dev-hub-client-id:
required: true
dev-hub-private-key:
required: true
gh-email:
required: true
github-token:
required: true

jobs:
create-test-scratch-org:
name: "Create Test Scratch Org"
runs-on: ubuntu-latest
container:
image: ghcr.io/muselab-d2x/d2x:cumulusci-next-snapshots
options: --user root
credentials:
username: "${{ github.actor }}"
password: "${{ secrets.github-token }}"
env:
DEV_HUB_AUTH_URL: "${{ secrets.dev-hub-auth-url }}"
DEV_HUB_USERNAME: "${{ secrets.dev-hub-username }}"
DEV_HUB_CLIENT_ID: "${{ secrets.dev-hub-client-id }}"
DEV_HUB_PRIVATE_KEY: "${{ secrets.dev-hub-private-key }}"
CUMULUSCI_SERVICE_github: '{ "username": "${{ github.actor }}", "token": "${{ secrets.github-token }}", "email": "${{ secrets.gh-email }}" }'
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Auth to DevHub
run: /usr/local/bin/devhub.sh

- name: Create Scratch Org
run: |
if [ -n "${{ inputs.scratchdef_path }}" ]; then
cci org scratch ${{ inputs.scratch_profile_name }} -f ${{ inputs.scratchdef_path }} ${{ inputs.cli_options }}
elif [ -n "${{ inputs.scratchdef_json }}" ]; then
echo "${{ inputs.scratchdef_json }}" > scratchdef.json
cci org scratch ${{ inputs.scratch_profile_name }} -f scratchdef.json ${{ inputs.cli_options }}
else
cci org scratch ${{ inputs.scratch_profile_name }} ${{ inputs.cli_options }}
fi
- name: Create Access Token Session Environment
run: |
ACCESS_TOKEN=$(cci org info ${{ inputs.scratch_profile_name }} --json | jq -r '.access_token')
INSTANCE_URL=$(cci org info ${{ inputs.scratch_profile_name }} --json | jq -r '.instance_url')
echo "ACCESS_TOKEN=${ACCESS_TOKEN}" >> $GITHUB_ENV
echo "INSTANCE_URL=${INSTANCE_URL}" >> $GITHUB_ENV
Loading

0 comments on commit 7fb7f49

Please sign in to comment.