Skip to content

Commit 95a3664

Browse files
committed
Copy .github/workflows/deploy.yml
1 parent d63bb4f commit 95a3664

File tree

1 file changed

+166
-0
lines changed

1 file changed

+166
-0
lines changed

.github/workflows/publish.yml

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# This action acts as a signal dispatcher that fires whenever the release process has
2+
# successfully completed. The listening workflow within the infra-k8s repository has
3+
# a corresponding event handler to generate releases based on this signal
4+
name: Deploy
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
# The only commits that will contain changes to the masterlist will be releases
11+
paths-ignore:
12+
- 'MASTERLIST.md'
13+
- 'package.json'
14+
- '.changeset/**'
15+
- 'packages/**/CHANGELOG.md'
16+
- 'packages/**/README.md'
17+
- 'packages/**/package.json'
18+
workflow_dispatch:
19+
inputs:
20+
# For this workflow, BUILD_ALL will cause all adapters to have their image built and deployed
21+
build-all:
22+
description: whether to run steps for all adapters, regardless of whether they were changed in this event
23+
required: false
24+
default: 'false'
25+
26+
concurrency:
27+
group: deploy-and-release
28+
cancel-in-progress: false
29+
30+
jobs:
31+
calculate-changes:
32+
name: Compute changed adapters
33+
runs-on: [ubuntu-latest]
34+
outputs:
35+
adapter-list: ${{ steps.changed-adapters.outputs.CHANGED_ADAPTERS }}
36+
tmp-branch: ${{ steps.push-branch.outputs.TMP_BRANCH }}
37+
steps:
38+
- name: Checkout Repo
39+
uses: actions/checkout@v4
40+
with:
41+
fetch-depth: 2
42+
- name: Set up and install dependencies
43+
uses: ./.github/actions/setup
44+
with:
45+
skip-setup: true
46+
- name: Build list of changed packages and changed adapters
47+
id: changed-adapters
48+
env:
49+
UPSTREAM_BRANCH: HEAD~1
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
run: |
52+
# The deployment will overwrite existing ones, so in order to calculate all adapters that have been changed,
53+
# we can mock running the changesets version command to have them present in the diff.
54+
# Additionally, running the changeset version will cause the images we publish here to have the proper increased version.
55+
yarn changeset version
56+
57+
# If there are changes, commit them and calculate the adapters.
58+
# If there are no changes, we don't need to deploy anything :)
59+
if [[ `git status --porcelain` ]]; then
60+
git commit -am "Mock changesets"
61+
fi
62+
63+
./.github/scripts/changed-adapters.sh
64+
# Since we want to publish with the versions updated, we need to store the changes we've made to a temporary branch
65+
- name: Publish branch
66+
id: push-branch
67+
if: steps.changed-adapters.outputs.CHANGED_ADAPTERS != '[]'
68+
run: |
69+
export TMP_BRANCH="tmp-deploy-$(git rev-parse HEAD)"
70+
git checkout -b tmp-deploy-$(git rev-parse HEAD)
71+
git push origin tmp-deploy-$(git rev-parse HEAD)
72+
echo "TMP_BRANCH=$TMP_BRANCH" >> $GITHUB_OUTPUT
73+
74+
publish-adapter-images:
75+
name: Build and publish ${{ matrix.adapter.shortName }}
76+
runs-on: ubuntu-latest
77+
needs:
78+
- calculate-changes
79+
if: needs.calculate-changes.outputs.adapter-list != '[]'
80+
environment: release
81+
permissions: # These are needed for the configure-aws-credentials action
82+
id-token: write
83+
contents: read
84+
strategy:
85+
max-parallel: 20
86+
matrix: ${{fromJson(needs.calculate-changes.outputs.adapter-list)}}
87+
env:
88+
ECR_URL: ${{ secrets.SDLC_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION_ECR_PRIVATE }}.amazonaws.com
89+
ECR_REPO: adapters/${{ matrix.adapter.shortName }}-adapter
90+
IMAGE_VERSION: ${{ matrix.adapter.version }}
91+
steps:
92+
- name: Check out code
93+
uses: actions/checkout@v4
94+
with:
95+
ref: ${{ needs.calculate-changes.outputs.tmp-branch }}
96+
- name: Build the adapter image
97+
uses: docker/build-push-action@ca877d9245402d1537745e0e356eab47c3520991 # v6.13.0
98+
with:
99+
context: .
100+
push: false
101+
tags: ${{ env.ECR_URL }}/${{ env.ECR_REPO }}:${{ matrix.adapter.version }}
102+
build-args: |
103+
package=${{ matrix.adapter.name }}
104+
location=${{ matrix.adapter.location }}
105+
- name: Debug
106+
run: docker image ls
107+
- name: Publish adapter image
108+
uses: ./.github/actions/publish-image
109+
with:
110+
image-version: ${{ matrix.adapter.version }}
111+
aws-ecr-url: ${{ env.ECR_URL }}
112+
aws-ecr-repo: ${{ env.ECR_REPO }}
113+
aws-region: ${{ secrets.AWS_REGION_ECR_PRIVATE }}
114+
aws-role: ${{ secrets.AWS_OIDC_IAM_ROLE_ARN }}
115+
aws-ecr-account-ids: ${{ secrets.AWS_PRIVATE_ECR_SECONDARY_ACCOUNT_ACCESS_IDS }}
116+
aws-ecr-private: true
117+
latest: true
118+
119+
deploy:
120+
name: Trigger infra deployment
121+
permissions:
122+
id-token: write
123+
contents: read
124+
runs-on: ubuntu-latest
125+
needs:
126+
- calculate-changes
127+
- publish-adapter-images
128+
if: needs.calculate-changes.outputs.adapter-list != '[]'
129+
environment: InfraK8s
130+
env:
131+
ECR_URL: ${{ secrets.SDLC_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION_ECR_PRIVATE }}.amazonaws.com
132+
CHANGED_ADAPTERS: ${{ needs.calculate-changes.outputs.adapter-list }}
133+
steps:
134+
- name: Setup GitHub Token
135+
id: setup-github-token
136+
uses: smartcontractkit/.github/actions/setup-github-token@9e7cc0779934cae4a9028b8588c9adb64d8ce68c # [email protected]
137+
with:
138+
aws-role-arn: ${{ secrets.AWS_ROLE_ARN_FOR_INFRA_K8s_PAT }}
139+
aws-lambda-url: ${{ secrets.GATI_LAMBDA_DATA_FEEDS_URL }}
140+
aws-region: ${{ secrets.AWS_REGION }}
141+
aws-role-duration-seconds: '1800' # this is optional and defaults to 900
142+
- name: Trigger Image Dispatcher
143+
run: >
144+
gh workflow run
145+
--repo smartcontractkit/infra-k8s
146+
--ref main "Infra-k8s Image Dispatcher"
147+
-F imageRepos="$(echo $CHANGED_ADAPTERS | jq -r "\"$ECR_URL/adapters/\" + (.adapter | .[].shortName) + \"-adapter\"" | tr '\n' ' ')"
148+
-F gitRepo=${{ github.event.repository.name }}
149+
env:
150+
GITHUB_TOKEN: ${{ steps.setup-github-token.outputs.access-token }}
151+
152+
cleanup:
153+
name: Clean up ephemeral items
154+
runs-on: ubuntu-latest
155+
needs:
156+
- calculate-changes
157+
- deploy
158+
if: always() && needs.calculate-changes.outputs.adapter-list != '[]'
159+
steps:
160+
- name: Check out code
161+
uses: actions/checkout@v4
162+
with:
163+
ref: ${{ needs.calculate-changes.outputs.tmp-branch }}
164+
- name: Delete ephemeral branch
165+
run: |
166+
git push origin --delete ${{ needs.calculate-changes.outputs.tmp-branch }}

0 commit comments

Comments
 (0)