Skip to content

dependency_update

dependency_update #63

Workflow file for this run

name: "Dependency Bot"
on:
repository_dispatch:
types:
- dependency_update
push:
branches:
- main
- "**"
jobs:
update-dependencies:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install dependencies (for `jq`)
run: sudo apt-get install jq
# Fetch the labels from the event payload
- name: Check for update label
id: label-check
run: |
# List of supported labels
SUPPORTED_LABELS=("alpha" "beta" "latest")
# Extract the labels from the event payload
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
LABELS=$(jq -r '.pull_request.labels[].name' <<< '${{ toJson(github.event) }}')
elif [[ "${{ github.event_name }}" == "repository_dispatch" ]]; then
LABELS=$(jq -r '.client_payload.labels[]' <<< '${{ toJson(github.event) }}')
else
LABELS=""
fi
# Default to "none" if no matching label is found
MATCHED_LABEL="none"
# Check if one of the supported labels is present
for label in $LABELS; do
for supported_label in "${SUPPORTED_LABELS[@]}"; do
if [[ "$label" == "$supported_label" ]]; then
MATCHED_LABEL=$label
break 2
fi
done
done
echo "Matched Label: $MATCHED_LABEL"
# Output the matched label
echo "matched_label=$MATCHED_LABEL" >> $GITHUB_ENV
# Conditionally run the dependency update based on the label
- name: Update dependencies if label matches
if: env.matched_label != 'none'
run: |
# List of packages to update
# PACKAGES=("@lit-protocol/lit-node-client" "another-package" "yet-another-package")
PACKAGES=("@lit-protocol/lit-node-client")
UPDATED_PACKAGES=()
UPDATED_VERSIONS=()
for package in "${PACKAGES[@]}"; do
# Update the package
yarn workspace lit-client-setup upgrade "$package@${{ env.matched_label }}"
# Get the updated version from package.json
VERSION=$(jq -r ".dependencies[\"$package\"]" < lib/package.json)
if [[ "$VERSION" != "null" ]]; then
# Store the updated package and its version
UPDATED_PACKAGES+=("$package")
UPDATED_VERSIONS+=("$VERSION")
else
echo "No updated version found for $package"
fi
done
# Remove ^ characters from versions
UPDATED_VERSIONS_CLEAN=()
for version in "${UPDATED_VERSIONS[@]}"; do
UPDATED_VERSIONS_CLEAN+=("${version#^}")
done
# Join the updated packages and versions into a string for output
UPDATED_PACKAGES_STR=$(IFS=, ; echo "${UPDATED_PACKAGES[*]}")
UPDATED_VERSIONS_STR=$(IFS=, ; echo "${UPDATED_VERSIONS_CLEAN[*]}")
echo "updated_packages=$UPDATED_PACKAGES_STR" >> $GITHUB_ENV
echo "updated_versions=$UPDATED_VERSIONS_STR" >> $GITHUB_ENV
# Get short SHA
- name: Get short SHA
id: slug
run: echo "::set-output name=sha7::$(echo ${GITHUB_SHA} | cut -c1-7)"
# Create a pull request after dependencies are updated
- name: Create Pull Request
if: env.matched_label != 'none'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "chore: update dependencies for ${{ env.matched_label }} label to versions: ${{ env.updated_versions }}"
branch: "update/dependencies-${{ env.matched_label }}-${{ env.updated_versions }}-${{ steps.slug.outputs.sha7 }}"
title: "[tag::${{ env.matched_label }}] Update dependencies to versions: ${{ env.updated_versions }}"
body: |
This pull request updates dependencies for the ${{ env.matched_label }} tag to the following versions:
- ${{ env.updated_packages }}: ${{ env.updated_versions }}
labels: ${{ env.matched_label }}