Skip to content

Commit

Permalink
Change commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jlantz committed Oct 18, 2024
1 parent 3c9673c commit 114fc3f
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 116 deletions.
90 changes: 90 additions & 0 deletions .github/workflows/build-feature-test-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Build 2GP 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-2gp-package-version:
name: "Create 2GP Package Version"
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
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
branches:
- main
- cumulusci-next**
paths:
- Dockerfile
- .github/workflows/build.yml
workflow_dispatch:

jobs:
Expand Down
98 changes: 43 additions & 55 deletions .github/workflows/feature-test-2gp-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ on:
required: false

jobs:
build-2gp-package-version:
# needs: check-build-status
# if: needs.check-build-status.outputs.should_build == 'true'
feature-test-and-snapshot:
name: "2GP Feature Test and PR Snapshot"
runs-on: ubuntu-latest
container:
Expand Down Expand Up @@ -81,62 +79,51 @@ jobs:
run: |
cci org default ${{ inputs.org_name }}
- name: Build Feature Test Package
id: create_2gp
run: |
cci flow run build_feature_test_package \
$([[ "${{ inputs.debug }}" == "true" ]] && echo " --debug")
shell: bash

- name: Set Commit Status
env:
GITHUB_TOKEN: "${{ secrets.github-token }}"
- name: Check Pull Request Conditions
id: check_conditions
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'
CONDITIONS_MET=false
if [[ "${{ inputs.create_pr_snapshot }}" == "true" ]]; then
cci task run github_pull_request_snapshot --check-only True --build-success True
SUCCESS_SKIP_REASON=$(cci history info last --json | jq -r '.return_values.skip_reason')
if [[ -z "$SUCCESS_SKIP_REASON" ]]; then
CONDITIONS_MET=true
else
echo "Success Snapshot Conditions Not Met: $SUCCESS_SKIP_REASON"
fi
fi
if [[ "${{ inputs.create_failure_snapshot }}" == "true" ]]; then
cci task run github_pull_request_snapshot --check-only True --build-success False
FAILURE_SKIP_REASON=$(cci history info last --json | jq -r '.return_values.skip_reason')
if [[ -z "$FAILURE_SKIP_REASON" ]]; then
CONDITIONS_MET=true
else
echo "Failure Snapshot Conditions Not Met: $FAILURE_SKIP_REASON"
fi
cci task run github_pull_request_snapshot --check-only True --build-success False --build-fail-tests True
FAILURE_TESTS_SKIP_REASON=$(cci history info last --json | jq -r '.return_values.skip_reason')
if [[ -z "$FAILURE_TESTS_SKIP_REASON" ]]; then
CONDITIONS_MET=true
else
echo "Failure Tests Snapshot Conditions Not Met: $FAILURE_TESTS_SKIP_REASON"
fi
fi
if [[ "$CONDITIONS_MET" == "false" ]]; then
echo "Snapshot Conditions Not Met for any outcome, skipping the build."
echo "skip_build=true" >> $GITHUB_OUTPUT
else
echo "skip_build=false" >> $GITHUB_OUTPUT
fi
shell: bash

feature-test-and-snapshot:
needs: build-2gp-package-version
name: "2GP Feature Test and PR Snapshot"
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 }}" }'
GITHUB_APP_ID: "${{ secrets.github-app-id }}"
GITHUB_APP_KEY: "${{ secrets.github-app-key }}"
steps:
- name: Checkout
uses: actions/checkout@v4

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

- name: Set ${{ inputs.org_name }} org as default org
run: |
cci org default ${{ inputs.org_name }}
- name: Prepare Feature Test Org
if: steps.check_conditions.outputs.skip_build == 'false'
id: prepare_org
run: |
cci flow run ci_feature_2gp --skip-from run_tests
- name: Start Snapshot Creation
if: inputs.create_pr_snapshot == true
if: steps.check_conditions.outputs.skip_build == 'false' && inputs.create_pr_snapshot == true
id: start_snapshot
run: |
cci task run github_pull_request_snapshot \
Expand All @@ -146,14 +133,15 @@ jobs:
shell: bash

- name: Run Feature Test
if: steps.check_conditions.outputs.skip_build == 'false'
id: feature_test
run: |
cci flow run ci_feature_2gp --start-from run_tests
shell: bash

- name: Finalize Snapshot Creation
if: always() && steps.check_conditions.outputs.skip_build == 'false' && (inputs.create_pr_snapshot == true || (inputs.create_failure_snapshot == true && (failure() || contains(steps.feature_test.outcome, 'failure'))))
id: finalize_snapshot
if: always() && (inputs.create_pr_snapshot == true || (inputs.create_failure_snapshot == true && (failure() || contains(steps.feature_test.outcome, 'failure'))))
env:
GITHUB_TOKEN: ${{ secrets.github-token }}
run: |
Expand All @@ -176,15 +164,15 @@ jobs:
shell: bash

- name: Delete Scratch Org
if: always()
if: always() && steps.check_conditions.outputs.skip_build == 'false'
run: cci org scratch_delete ${{ inputs.org_name }}
shell: bash

- name: Check Job Status
if: always()
if: always() && steps.check_conditions.outputs.skip_build == 'false'
run: |
if [[ "${{ steps.create_2gp.outcome }}" == "failure" || "${{ steps.prepare_org.outcome }}" == "failure" || "${{ steps.feature_test.outcome }}" == "failure" ]]; then
if [[ "${{ steps.prepare_org.outcome }}" == "failure" || "${{ steps.feature_test.outcome }}" == "failure" ]]; then
echo "Critical step failed. Failing the job."
exit 1
fi
shell: bash
shell: bash
88 changes: 28 additions & 60 deletions .github/workflows/feature-test-2gp.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: 2GP Feature Test

on:
workflow_call:
inputs:
Expand All @@ -19,7 +18,6 @@ on:
type: string
required: false
default: cumulusci-next-snapshots

secrets:
dev-hub-auth-url:
required: false
Expand All @@ -39,58 +37,8 @@ on:
required: false

jobs:
create-2gp-package-version:
name: "Create 2GP Package Version"
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
feature-test-2gp:
name: "Feature Test 2GP"
needs: create-2gp-package-version
runs-on: ubuntu-latest
container:
image: ${{ inputs.docker_image }}:${{ inputs.docker_tag }}
Expand All @@ -103,22 +51,25 @@ jobs:
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
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 }}"
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: Run Feature Test
id: feature_test
env:
GITHUB_TOKEN: "${{ secrets.github-token }}"
CUMULUSCI_SERVICE_github: '{ "username": "${{ github.actor }}", "token": "${{ secrets.github-token }}", "email": "${{ secrets.gh-email }}" }'
Expand Down Expand Up @@ -150,7 +101,24 @@ jobs:
path: cci_build_history.json

- name: Delete Scratch Org
if: ${{ always() }}
run: |
cci org scratch_delete feature
if: always()
run: cci org scratch_delete feature
shell: bash

- name: Check Job Status
if: always()
run: |
if [[ "${{ steps.feature_test.outcome }}" == "failure" ]]; then
echo "Feature Test step failed. Failing the job."
exit 1
fi
# Check for any failed steps
FAILED_STEPS=$(cat $GITHUB_OUTPUT | grep -c "failure")
if [[ $FAILED_STEPS -gt 0 ]]; then
echo "One or more steps failed. Failing the job."
exit 1
fi
echo "All steps completed successfully."
shell: bash
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | g
apt-get update && apt-get install -y gh

# Install CumulusCI
RUN pip --no-cache-dir install git+https://github.com/muselab-d2x/CumulusCI@a8e9f4dd83cb8fe761621e0a7e57e2e2fe834013 cookiecutter keyrings.alt
RUN pip --no-cache-dir install git+https://github.com/muselab-d2x/CumulusCI@a3dfddada3beb1f6e67522e9f660b8e5190975d2 cookiecutter keyrings.alt

# Copy devhub auth script and make it executable
COPY devhub.sh /usr/local/bin/devhub.sh
Expand Down

0 comments on commit 114fc3f

Please sign in to comment.