Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/scripts/changed-adapters.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/bin/bash -e

# If BUILD_ALL is true, then we want to generate lists with all packages regardless of changes
# If ADAPTER_NAMES is set, then we want to generate lists with only those adapters. ADAPTER_NAMES should be a comma-separated list of short names (e.g. "coinpaprika,coingecko")
if [[ $BUILD_ALL = true ]]; then
PACKAGE_LIST=$(yarn workspaces list -R --json)
elif [[ -n "$ADAPTER_NAMES" ]]; then
PACKAGE_LIST=$(yarn workspaces list -R --json | jq --arg list "$ADAPTER_NAMES" '($list | split(",")) as $shortNames | select(.name as $name | $shortNames | any($name == "@chainlink/" + . + "-adapter"))')
else
PACKAGE_LIST=$(yarn workspaces list -R --json --since=$UPSTREAM_BRANCH)
fi
Expand Down
70 changes: 70 additions & 0 deletions .github/workflows/deploy-from-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# This workflow is triggered by PRs that propose a release. It publishes docker
# images and deploys them to infra-k8s for the adapters proposed to release.
#
# Because building and deploying are only allowed from a protected branch, and
# this workflow is triggered by pull requests, it dispatches to another
# workflow to do the actual work.
name: Deploy

on:
pull_request:
branches:
- main
# The only commits that will contain changes to the masterlist will be releases
paths:
- 'MASTERLIST.md'

concurrency:
group: deploy-and-release
cancel-in-progress: false

jobs:
calculate-changes:
name: Compute changed adapters
permissions:
contents: read
runs-on: [ubuntu-latest]
outputs:
adapter-list: ${{ steps.changed-adapters.outputs.CHANGED_ADAPTERS }}
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 2
- name: Build list of changed packages and changed adapters
id: changed-adapters
env:
UPSTREAM_BRANCH: HEAD~1
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
./.github/scripts/changed-adapters.sh
disaptch:
name: Trigger the deploy workflow
permissions:
contents: read
actions: write
runs-on: ubuntu-latest
needs:
- calculate-changes
if: needs.calculate-changes.outputs.adapter-list != '[]'
env:
CHANGED_ADAPTERS: ${{ needs.calculate-changes.outputs.adapter-list }}
PR_BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Determine infra-k8s branch name suffix
id: suffix
run: |
# If the branch name is 'changeset-release/main', then this is the
# PR to release all changed adapters so we don't use a suffix.
if [[ "$PR_BRANCH_NAME" = "changeset-release/main" ]]; then
echo "SUFFIX=" >> $GITHUB_OUTPUT
else
echo "SUFFIX=-pr${{ github.event.number }}" >> $GITHUB_OUTPUT
fi
- name: Trigger deploy workflow
run: >
gh workflow run "Deploy"
--ref main
-F adapters="$(echo $CHANGED_ADAPTERS | jq -r "(.adapter | .[].shortName)" | tr '\n' ',')"
-F infra-k8s-branch-suffix="${{ steps.suffix.outputs.SUFFIX }}"
69 changes: 11 additions & 58 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,15 @@
name: Deploy

on:
push:
branches:
- main
# The only commits that will contain changes to the masterlist will be releases
paths-ignore:
- 'MASTERLIST.md'
- 'package.json'
- '.changeset/**'
- 'packages/**/CHANGELOG.md'
- 'packages/**/README.md'
- 'packages/**/package.json'
workflow_dispatch:
inputs:
# For this workflow, BUILD_ALL will cause all adapters to have their image built and deployed
build-all:
description: whether to run steps for all adapters, regardless of whether they were changed in this event
adapters:
description: Names of adapters to deploy
required: true
infra-k8s-branch-suffix:
description: Suffix to append to infra-k8s branch name. Must be non-empty if not triggered by the full release PR.
required: false
default: 'false'
default: ''

concurrency:
group: deploy-and-release
Expand All @@ -33,42 +24,16 @@ jobs:
runs-on: [ubuntu-latest]
outputs:
adapter-list: ${{ steps.changed-adapters.outputs.CHANGED_ADAPTERS }}
tmp-branch: ${{ steps.push-branch.outputs.TMP_BRANCH }}
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 2
- name: Set up and install dependencies
uses: ./.github/actions/setup
with:
skip-setup: true
- name: Build list of changed packages and changed adapters
id: changed-adapters
env:
UPSTREAM_BRANCH: HEAD~1
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ADAPTER_NAMES: ${{ github.event.inputs.adapters }}
run: |
# The deployment will overwrite existing ones, so in order to calculate all adapters that have been changed,
# we can mock running the changesets version command to have them present in the diff.
# Additionally, running the changeset version will cause the images we publish here to have the proper increased version.
yarn changeset version

# If there are changes, commit them and calculate the adapters.
# If there are no changes, we don't need to deploy anything :)
if [[ `git status --porcelain` ]]; then
git commit -am "Mock changesets"
fi

./.github/scripts/changed-adapters.sh
# Since we want to publish with the versions updated, we need to store the changes we've made to a temporary branch
- name: Publish branch
id: push-branch
if: steps.changed-adapters.outputs.CHANGED_ADAPTERS != '[]'
run: |
export TMP_BRANCH="tmp-deploy-$(git rev-parse HEAD)"
git checkout -b tmp-deploy-$(git rev-parse HEAD)
git push origin tmp-deploy-$(git rev-parse HEAD)
echo "TMP_BRANCH=$TMP_BRANCH" >> $GITHUB_OUTPUT

create-ecr:
name: Create ECR for ${{ matrix.adapter.shortName }}
Expand Down Expand Up @@ -147,6 +112,7 @@ jobs:
env:
ECR_URL: ${{ secrets.SDLC_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION_ECR_PRIVATE }}.amazonaws.com
CHANGED_ADAPTERS: ${{ needs.calculate-changes.outputs.adapter-list }}
BRANCH_SUFFIX: ${{ github.event.inputs.infra-k8s-branch-suffix }}
steps:
- name: Setup GitHub Token
id: setup-github-token
Expand All @@ -158,25 +124,12 @@ jobs:
aws-role-duration-seconds: '1800' # this is optional and defaults to 900
- name: Trigger Image Dispatcher
run: >
# gitRepo does not need to be an actual repo name. It is only used
# in the branch name, PR title, and PR description in infra-k8s.
gh workflow run
--repo smartcontractkit/infra-k8s
--ref main "Infra-k8s Image Dispatcher"
-F imageRepos="$(echo $CHANGED_ADAPTERS | jq -r "\"$ECR_URL/adapters/\" + (.adapter | .[].shortName) + \"-adapter\"" | tr '\n' ' ')"
-F gitRepo=${{ github.event.repository.name }}
-F gitRepo="${{ github.event.repository.name }}$BRANCH_SUFFIX"
env:
GITHUB_TOKEN: ${{ steps.setup-github-token.outputs.access-token }}

cleanup:
name: Clean up ephemeral items
runs-on: ubuntu-latest
needs:
- calculate-changes
- deploy
if: always() && needs.calculate-changes.outputs.adapter-list != '[]'
steps:
- uses: actions/checkout@v5
with:
ref: ${{ needs.calculate-changes.outputs.tmp-branch }}
- name: Delete ephemeral branch
run: |
git push origin --delete ${{ needs.calculate-changes.outputs.tmp-branch }}
Loading