-
Notifications
You must be signed in to change notification settings - Fork 10
153 lines (142 loc) · 7.02 KB
/
feature-test-snapshot.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
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