-
Notifications
You must be signed in to change notification settings - Fork 0
175 lines (151 loc) · 6.01 KB
/
dependency-zip.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# This workflow checks if a dependency zip file that matches the current working branch exists in an S3 bucket.
name: Dependency zip
on:
workflow_call:
inputs:
repository:
description: "Dependency repository to checkout"
required: true
type: string
main-branch:
description: "Main branch of the dependency repository"
required: false
type: string
default: "main"
secrets:
GITHUB_CHECKOUT_TOKEN:
description: "GitHub token to use for the checkout"
required: true
PACKAGED_ZIP_BUCKET:
description: "S3 bucket where the dependency zip is stored"
required: true
S3_ACCESS_KEY_ID:
description: "S3 access key ID"
required: true
S3_SECRET_ACCESS_KEY:
description: "S3 secret access key"
required: true
PACKAGED_ZIP_REGION:
description: "S3 region where the dependency zip is stored"
required: true
S3_ENDPOINT:
description: "S3 endpoint"
required: true
outputs:
use-release:
description: "Whether to use the release zip"
value: ${{ jobs.check-zip.outputs.use-release }}
s3-zip-name:
description: "Name of the dependency zip file in S3"
value: ${{ jobs.check-zip.outputs.s3-zip-name }}
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
checkout-path: ${{ steps.checkout_path.outputs.path }}
head-branch: ${{ steps.branch_values.outputs.head_branch }}
base-branch: ${{ steps.branch_values.outputs.base_branch }}
is-main: ${{ steps.branch_values.outputs.head_branch == inputs.main-branch }}
steps:
- name: Define the checkout path
id: checkout_path
run: |
repository=${{ inputs.repository }}
echo "path=${repository//\//_}" >> $GITHUB_OUTPUT
- name: Define the head and base branches
id: branch_values
run: |
if [ -z "$GITHUB_HEAD_REF" ]; then
echo "head_branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
else
echo "head_branch=$GITHUB_HEAD_REF" >> $GITHUB_OUTPUT
fi
if [ -z "$GITHUB_BASE_REF" ]; then
echo "base_branch=${{ inputs.main-branch }}" >> $GITHUB_OUTPUT
else
echo "base_branch=$GITHUB_BASE_REF" >> $GITHUB_OUTPUT
fi
check-branch:
runs-on: ubuntu-latest
needs:
- prepare
outputs:
branch-to-checkout: ${{ steps.output_values.outputs.dependency_branch }}
is-main: ${{ steps.output_values.outputs.dependency_branch == inputs.main-branch }}
steps:
- name: Checkout dependency to verify the available branches
if: ${{ needs.prepare.outputs.is-main == 'false' }}
uses: actions/checkout@v4
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.main-branch }}
path: ${{ needs.prepare.outputs.checkout-path }}
fetch-depth: 1
token: ${{ secrets.GITHUB_CHECKOUT_TOKEN }}
- name: Check if the required branch exists
id: output_values
run: |
if [ "${{ needs.prepare.outputs.is-main }}" = "true" ]; then
echo "dependency_branch=${{ inputs.main-branch }}" >> $GITHUB_OUTPUT
exit 0
fi
cd ${{ needs.prepare.outputs.checkout-path }}
head_branch_exists=$(git ls-remote --heads origin ${{ needs.prepare.outputs.head-branch }} | wc -l)
if [ $head_branch_exists -eq 1 ]; then
echo "dependency_branch=${{ needs.prepare.outputs.head-branch }}" >> $GITHUB_OUTPUT
else
base_branch_exists=$(git ls-remote --heads origin ${{ needs.prepare.outputs.base-branch }} | wc -l)
if [ $base_branch_exists -eq 1 ]; then
echo "dependency_branch=${{ needs.prepare.outputs.base-branch }}" >> $GITHUB_OUTPUT
else
echo "dependency_branch=${{ inputs.main-branch }}" >> $GITHUB_OUTPUT
fi
fi
check-zip:
runs-on: ubuntu-latest
needs:
- prepare
- check-branch
outputs:
use-release: ${{ steps.output_values.outputs.use-release }}
s3-zip-name: ${{ steps.output_values.outputs.s3-zip-name }}
steps:
- name: Checkout dependency
if: ${{ needs.check-branch.outputs.is-main == 'false' }}
uses: actions/checkout@v4
with:
repository: ${{ inputs.repository }}
ref: ${{ needs.check-branch.outputs.branch-to-checkout }}
path: ${{ needs.prepare.outputs.checkout-path }}
fetch-depth: 1
token: ${{ secrets.GITHUB_CHECKOUT_TOKEN }}
- name: Define the dependency zip name
if: ${{ needs.check-branch.outputs.is-main == 'false' }}
run: |
cd ${{ needs.prepare.outputs.checkout-path }}
composer -- pup
version=$(composer -- pup get-version --dev)
echo "DEPENDENCY_ZIP_NAME=$(composer -- pup zip-name $version).zip" >> $GITHUB_ENV
- name: Check if the zip exists in S3
if: ${{ needs.check-branch.outputs.is-main == 'false' }}
uses: the-events-calendar/action-s3-utility@main
id: s3_zip_exists
continue-on-error: true
env:
S3_BUCKET: ${{ secrets.PACKAGED_ZIP_BUCKET }}
S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}
S3_REGION: ${{ secrets.PACKAGED_ZIP_REGION }}
S3_ENDPOINT: ${{ secrets.S3_ENDPOINT }}
COMMAND: exists
FILE: "${{ env.DEPENDENCY_ZIP_NAME }}"
- name: Set output values
id: output_values
run: |
# use the release zip if the file does not exists or is main
if [ "${{ needs.check-branch.outputs.is-main }}" = "true" ] || [ "${{ steps.s3_zip_exists.outcome }}" != "success" ]; then
echo 'use-release=true' >> $GITHUB_OUTPUT
else
echo 'use-release=false' >> $GITHUB_OUTPUT
echo "s3-zip-name=${{ env.DEPENDENCY_ZIP_NAME }}" >> $GITHUB_OUTPUT
fi