Skip to content

Commit

Permalink
new snapshots workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
jlantz committed Oct 10, 2024
1 parent e5de50f commit 7e482b5
Show file tree
Hide file tree
Showing 2 changed files with 232 additions and 103 deletions.
180 changes: 77 additions & 103 deletions .github/workflows/feature-test-2gp-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,120 +70,94 @@ 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@v2

- name: Auth to DevHub
run: /usr/local/bin/devhub.sh
- 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 }}
cci org info feature
- name: Set ${{ inputs.org_name }} org as default org
run: |
cci org default ${{ inputs.org_name }}
cci org info feature
- name: Build Feature Test Package
id: create_2gp
run: |
set -e {
- name: Build Feature Test Package
id: create_2gp
run: |
cci flow run build_feature_test_package \
$([[ "${{ inputs.debug }}" == "true" ]] && echo " --debug") | tee cumulusci-flow.log
} || {
echo "::error::Build failed. Please review the logs for more information."}
cci error info
exit 1
}
shell: bash
$([[ "${{ inputs.debug }}" == "true" ]] && echo " --debug")
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
- 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: Prepare Feature Test Org
id: prepare_org
run: |
cci flow run ci_feature_2gp --skip-from run_tests
continue-on-error: true
- 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: |
set -e
{
- 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
} || {
echo "::error::Snapshot creation failed. Please review the logs for more information."}
cci error info
exit 1
}
shell: bash
--wait False \
--build-success ${{ job.status == 'success' }} \
--is-packaged true
shell: bash

- name: Run Feature Test
id: feature_test
if: steps.prepare_org.outcome == 'success'
run: |
set -e
{
cci flow run ci_feature_2gp --start-from run_tests
} || {
echo "::error::Apex test failure. Please review the logs for more information."}
cci error info
exit 1
}
continue-on-error: true

- name: Finalize Snapshot Creation
id: finalize_snapshot
if: (inputs.create_pr_snapshot == true && "${{ steps.start_snapshot.outputs.SNAPSHOT_ID}}" != "") || (inputs.create_failure_snapshot == true && job.status != 'success')
env:
GITHUB_TOKEN: ${{ secrets.github-token }}
run: |
- name: Run Feature Test
id: feature_test
run: |
cci flow run ci_feature_2gp --start-from run_tests
shell: bash

set -e
{
# If the snapshot creation task was run, finalize the snapshot
- 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.outputs.*, 'ApexTestException') }}" \
--snapshot-is-packaged true \
$([[ -n "${{ inputs.create_snapshot_commit_status }}" ]] && echo "--create-commit-status ${{ inputs.create_snapshot_commit_status }}") \
$([[ -n "${{ inputs.create_snapshot_environment }}" ]] && echo "--create-environment-status ${{ inputs.create_snapshot_environment }}")
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

# If the snapshot creation task was not run, create a snapshot if the build failed
elif [[ "${{ inputs.create_failure_snapshot }}" == "true" && "${{ job.status }}" != "success" ]]; then
cci task run github_pull_request_snapshot \
--build-success false \
--build-fail-tests "${{ contains(steps.feature_test.outputs.*, 'ApexTestException') }}" \
--snapshot-is-packaged true \
$([[ -n "${{ inputs.create_snapshot_commit_status }}" ]] && echo "--create-commit-status ${{ inputs.create_snapshot_commit_status }}") \
$([[ -n "${{ inputs.create_snapshot_environment }}" ]] && echo "--create-environment-status ${{ inputs.create_snapshot_environment }}")
fi
} || {
echo "::error::Apex test failure. Please review the logs for more information."}
cci error info
- 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
}
shell: bash

- name: Delete Scratch Org
if: ${{ always() }}
run: cci org scratch_delete ${{ inputs.org_name }}
shell: bash
fi
shell: bash
155 changes: 155 additions & 0 deletions .github/workflows/feature-test-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
name: Unmanaged Feature Test and PR Snapshot
on:
workflow_call:
inputs:
debug:
required: false
default: false
description: "Enable debug logging output for CumulusCI"
type: boolean
org_name:
required: false
default: feature
description: "The name of the scratch org profile to use for the source org. If not provided, the org named 'feature' will be used."
type: string
create_pr_snapshot:
required: false
default: false
description: "If true, snapshot functionality is enabled for pull requests. CumulusCI's logic will determine if a snapshot should be created via the github_pull_request_snapshot task."
type: boolean
create_failure_snapshot:
required: false
default: false
description: "If true, a snapshot will be created if the build fails. CumulusCI's logic will determine if a snapshot should be created via the github_pull_request_snapshot task."
type: boolean
create_snapshot_commit_status:
required: false
default: false
description: "If true, a commit status will be set for the build. This is useful for tracking the status of the snapshot creation task."
type: boolean
create_snapshot_environment:
required: false
default: false
description: "If true, a GitHub Environment will be created for the snapshot."
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:
feature-test-and-snapshot:
# needs: check-build-status
# if: needs.check-build-status.outputs.should_build == 'true'
name: "Unmanaged 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@v2

- 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 }}
cci org info feature
- name: Prepare Feature Test Org
id: prepare_org
run: |
cci flow run ci_feature --skip-from run_tests --use-snapshots
- 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 false
shell: bash

- name: Run Feature Test
id: feature_test
run: |
cci flow run ci_feature --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 false \
$([[ "${{ 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 false \
$([[ "${{ 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: Capture CumulusCI Build History
if: always()
run: |
cci history list --json > cci_build_history.json
shell: bash

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

- 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

0 comments on commit 7e482b5

Please sign in to comment.