Skip to content

Commit

Permalink
Prepare feature-test-2gp workflow for use with predictive snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
jlantz committed Oct 17, 2024
1 parent b420638 commit 3e1dd7d
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 124 deletions.
191 changes: 109 additions & 82 deletions .github/workflows/feature-test-2gp-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ on:
required: false

jobs:
feature-test-and-snapshot:
build-2gp-package-version:
# needs: check-build-status
# if: needs.check-build-status.outputs.should_build == 'true'
name: "2GP Feature Test and PR Snapshot"
Expand All @@ -70,94 +70,121 @@ jobs:
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@v2
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: Auth to DevHub
run: /usr/local/bin/devhub.sh
- 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 ${{ inputs.org_name }} org as default org
run: |
cci org default ${{ inputs.org_name }}
cci org info feature
- 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

- name: Build Feature Test Package
id: create_2gp
run: |
cci flow run build_feature_test_package \
$([[ "${{ inputs.debug }}" == "true" ]] && echo " --debug")
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: 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
- name: Auth to DevHub
run: /usr/local/bin/devhub.sh

- name: Prepare Feature Test Org
id: prepare_org
run: |
cci flow run ci_feature_2gp --skip-from run_tests
- name: Set ${{ inputs.org_name }} org as default org
run: |
cci org default ${{ inputs.org_name }}
- name: Prepare Feature Test Org
id: prepare_org
run: |
cci flow run ci_feature_2gp --skip-from run_tests
- name: Start Snapshot Creation
if: inputs.create_pr_snapshot == true
id: start_snapshot
run: |
cci task run github_pull_request_snapshot \
--wait False \
--build-success ${{ job.status == 'success' }} \
--is-packaged true
shell: bash
- name: Start Snapshot Creation
if: inputs.create_pr_snapshot == true
id: start_snapshot
run: |
cci task run github_pull_request_snapshot \
--wait False \
--build-success ${{ job.status == 'success' }} \
--is-packaged true
shell: bash

- name: Run Feature Test
id: feature_test
run: |
cci flow run ci_feature_2gp --start-from run_tests
shell: bash
- name: Run Feature Test
id: feature_test
run: |
cci flow run ci_feature_2gp --start-from run_tests
shell: bash

- name: Finalize Snapshot Creation
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: |
if [[ "${{ inputs.create_pr_snapshot }}" == "true" && -n "${{ steps.start_snapshot.outputs.SNAPSHOT_ID }}" ]]; then
cci task run github_pull_request_snapshot \
--snapshot-id "${{ steps.start_snapshot.outputs.SNAPSHOT_ID }}" \
--build-success "${{ job.status == 'success' }}" \
--build-fail-tests "${{ contains(steps.feature_test.outcome, 'failure') }}" \
--snapshot-is-packaged true \
$([[ "${{ inputs.create_snapshot_commit_status }}" == "true" ]] && echo "--create-commit-status true") \
$([[ "${{ inputs.create_snapshot_environment }}" == "true" ]] && echo "--create-environment-status true")
elif [[ "${{ inputs.create_failure_snapshot }}" == "true" && ("${{ failure() }}" == "true" || "${{ contains(steps.feature_test.outcome, 'failure') }}" == "true") ]]; then
cci task run github_pull_request_snapshot \
--build-success false \
--build-fail-tests "${{ contains(steps.feature_test.outcome, 'failure') }}" \
--snapshot-is-packaged true \
$([[ "${{ inputs.create_snapshot_commit_status }}" == "true" ]] && echo "--create-commit-status true") \
$([[ "${{ inputs.create_snapshot_environment }}" == "true" ]] && echo "--create-environment-status true")
fi
shell: bash
- name: Finalize Snapshot Creation
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: |
if [[ "${{ inputs.create_pr_snapshot }}" == "true" && -n "${{ steps.start_snapshot.outputs.SNAPSHOT_ID }}" ]]; then
cci task run github_pull_request_snapshot \
--snapshot-id "${{ steps.start_snapshot.outputs.SNAPSHOT_ID }}" \
--build-success "${{ job.status == 'success' }}" \
--build-fail-tests "${{ contains(steps.feature_test.outcome, 'failure') }}" \
--snapshot-is-packaged true \
$([[ "${{ inputs.create_snapshot_commit_status }}" == "true" ]] && echo "--create-commit-status true") \
$([[ "${{ inputs.create_snapshot_environment }}" == "true" ]] && echo "--create-environment-status true")
elif [[ "${{ inputs.create_failure_snapshot }}" == "true" && ("${{ failure() }}" == "true" || "${{ contains(steps.feature_test.outcome, 'failure') }}" == "true") ]]; then
cci task run github_pull_request_snapshot \
--build-success false \
--build-fail-tests "${{ contains(steps.feature_test.outcome, 'failure') }}" \
--snapshot-is-packaged true \
$([[ "${{ inputs.create_snapshot_commit_status }}" == "true" ]] && echo "--create-commit-status true") \
$([[ "${{ inputs.create_snapshot_environment }}" == "true" ]] && echo "--create-environment-status true")
fi
shell: bash

- name: Delete Scratch Org
if: always()
run: cci org scratch_delete ${{ inputs.org_name }}
shell: bash
- name: Delete Scratch Org
if: always()
run: cci org scratch_delete ${{ inputs.org_name }}
shell: bash

- name: Check Job Status
if: always()
run: |
if [[ "${{ steps.create_2gp.outcome }}" == "failure" || "${{ steps.prepare_org.outcome }}" == "failure" || "${{ steps.feature_test.outcome }}" == "failure" ]]; then
echo "Critical step failed. Failing the job."
exit 1
fi
shell: bash
- name: Check Job Status
if: always()
run: |
if [[ "${{ steps.create_2gp.outcome }}" == "failure" || "${{ steps.prepare_org.outcome }}" == "failure" || "${{ steps.feature_test.outcome }}" == "failure" ]]; then
echo "Critical step failed. Failing the job."
exit 1
fi
shell: bash
112 changes: 70 additions & 42 deletions .github/workflows/feature-test-2gp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,53 +39,15 @@ on:
required: false

jobs:
# select_d2x_docker_image:
# name: "Select D2X Docker Image"
# runs-on: ubuntu-latest
# outputs:
# tag_suffix: ${{ steps.set_tag_suffix.outputs.tag_suffix }}
# steps:
# - name: Calculate tag suffix
# id: set_tag_suffix
# run: |
# TAG_SUFFIX=""
# if [ "${{ inputs.with_full_browser }}" == "true" ]; then
# TAG_SUFFIX=-full-browser
# echo "Using full-browser image" >> $GITHUB_STEP_SUMMARY
# elif [ "${{ inputs.with_chromedriver }}" == "true" ] && [ "${{ inputs.with_playwright }}" == "true" ]; then
# TAG_SUFFIX=-full-browser
# echo "Using full-browser image" >> $GITHUB_STEP_SUMMARY
# elif [ "${{ inputs.with_chromedriver }}" == "true" ]; then
# TAG_SUFFIX=-chromedriver
# echo "Using chromedriver image" >> $GITHUB_STEP_SUMMARY
# elif [ "${{ inputs.with_playwright }}" == "true" ]; then
# TAG_SUFFIX=-playwright
# echo "Using playwright image" >> $GITHUB_STEP_SUMMARY
# else
# TAG_SUFFIX=""
# echo "Using default image" >> $GITHUB_STEP_SUMMARY
# fi
# echo "tag_suffix=$TAG_SUFFIX" >> $GITHUB_OUTPUT

feature-test:
name: "2GP Feature Test"
create-2gp-package-version:
name: "Create 2GP Package Version"
runs-on: ubuntu-latest
# needs: select_d2x_docker_image
container:
image: ${{ inputs.docker_image }}:${{ inputs.docker_tag }}
# image: ${{ inputs.docker_image }}:${{ inputs.docker_tag }}${{ needs.select_d2x_docker_image.outputs.tag_suffix }}
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: D2X Image Details
run: |
Expand All @@ -94,14 +56,23 @@ jobs:
echo "D2X Docker Image: `${{ inputs.docker_image }}:${{ inputs.docker_tag }}`" >> $GITHUB_STEP_SUMMARY
shell: bash
- name: Checkout
uses: actions/checkout@v3
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
Expand All @@ -117,10 +88,67 @@ jobs:
-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 }}
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: Run Feature Test
env:
GITHUB_TOKEN: "${{ secrets.github-token }}"
run: cci flow run ci_feature_2gp
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 --use-snapshots

- name: Capture CumulusCI Build History
if: always()
run: |
cci history list
cci history dependencies
cci history dependencies --json > cci_dependencies_history.json
cci history list --json > cci_build_history.json
shell: bash

- name: Upload CumulusCI Dependencies History
if: always()
uses: actions/upload-artifact@v4
with:
name: cci-dependencies-history
path: cci_dependencies_history.json

- name: Upload CumulusCI Build History
if: always()
uses: actions/upload-artifact@v4
with:
name: cci-build-history
path: cci_build_history.json

- name: Delete Scratch Org
if: ${{ always() }}
run: |
Expand Down

0 comments on commit 3e1dd7d

Please sign in to comment.