forked from DroidKaigi/conference-app-2024
-
Notifications
You must be signed in to change notification settings - Fork 0
124 lines (115 loc) · 4.93 KB
/
stage-app-pull-request.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
name: stage-app-pull-request
on:
workflow_run:
workflows:
- build
types:
- completed
# Disable all permissions. We have to enable required permissions at job-level.
permissions: {}
jobs:
stage-epic:
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
permissions:
actions: read # for listJobsForWorkflowRun and listWorkflowRunArtifacts
contents: read # for checkout
deployments: write # for create-deployment
pull-requests: read # for listing pull requests
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
repository: droidkaigi/conference-app-2024
ref: gh-actions
path: gh-actions
- uses: actions/github-script@v7
id: get-pr
with:
script: |
const headBranch = '${{ format('{0}:{1}', github.event.workflow_run.head_repository.owner.login, github.event.workflow_run.head_branch) }}'
const { data: pulls } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
head: headBranch,
direction: 'desc',
sort: 'updated',
per_page: 1
})
if (pulls.length === 0) {
return '[halt]'
} else {
return pulls[0]
}
- uses: actions/github-script@v7
id: get-artifact-id
if: steps.get-pr.outputs.result != '[halt]'
with:
result-encoding: string
script: |
const { data: resp } = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }}
})
const artifact = resp.artifacts.find((a) => a.name === "build-outputs")
if (artifact) {
return artifact.id
} else {
return '[halt]'
}
- uses: ./gh-actions/actions/get-artifact
id: get-artifact
if: steps.get-artifact-id.outputs.result != '[halt]'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
artifact-id: ${{ steps.get-artifact-id.outputs.result }}
path: ~/build-outputs
- run: >
unzip ${{ steps.get-artifact.outputs.archive-path }} -d ~/build-outputs &&
rm -f ${{ steps.get-artifact.outputs.archive-path }}
- uses: ./gh-actions/actions/find-files
id: find-dev-debug-apk
with:
pattern: "~/build-outputs/**/app-android-dev-debug.apk"
- uses: ./gh-actions/actions/create-deployment
id: create-deployment
with:
github-token: ${{ github.token }}
ref: refs/pull/${{ fromJSON(steps.get-pr.outputs.result).number }}/head
sha: ${{ fromJSON(steps.get-pr.outputs.result).head.sha }}
artifact-name: build-outputs
environment: deploygate-distribution
- uses: jmatsu/[email protected]
id: upload
continue-on-error: true
with:
app_owner_name: droidkaigi
api_token: ${{ secrets.DEPLOYGATE_API_TOKEN }}
app_file_path: ${{ fromJSON(steps.find-dev-debug-apk.outputs.paths)[0] }}
message: GitHub Actions have staged an artifact of ${{ fromJSON(steps.get-pr.outputs.result).number }}/head / ${{ fromJSON(steps.get-pr.outputs.result).head.sha }}
distribution_find_by: name
distribution_id: ${{ format('debug/refs/pull/{0}/head', fromJSON(steps.get-pr.outputs.result).number) }}
release_note: ${{ format('Workflow {0}/{1} based on {2}', github.run_id , github.run_number , fromJSON(steps.get-pr.outputs.result).head.sha) }}
pin: false
- name: generate properties based on upload step's status
id: deployment-properties
if: steps.upload.conclusion == 'success'
run: |
if [[ "${{ steps.upload.outcome }}" == "success" ]]; then
echo "deployment-url=${{ steps.upload.outputs.distribution_url }}" >> "$GITHUB_OUTPUT"
echo "description=Deployed an app successfully. Please try it through DeployGate!" >> "$GITHUB_OUTPUT"
else
echo "deployment-url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> "$GITHUB_OUTPUT"
echo "description=Staging an app failed. Please check the workflow." >> "$GITHUB_OUTPUT"
fi
- uses: ./gh-actions/actions/commit-deployment
if: steps.upload.conclusion == 'success'
with:
github-token: ${{ github.token }}
deployment-id: ${{ fromJSON(steps.create-deployment.outputs.deployment).id }}
state: ${{ steps.upload.outcome }}
deployment-url: ${{ steps.deployment-properties.outputs.deployment-url }}
description: ${{ steps.deployment-properties.outputs.description }}