Fix failure() #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
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 && (steps.feature_test.outcome == 'failure' || steps.prepare_org.outcome == 'failure' || steps.create_2gp.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 "${{ 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" && ("${{ steps.feature_test.outcome }}" == "failure" || "${{ steps.prepare_org.outcome }}" == "failure" || "${{ steps.create_2gp.outcome }}" == "failure") ]]; then | ||
cci task run github_pull_request_snapshot \ | ||
--build-success false \ | ||
--build-fail-tests "${{ 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: 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 |