dependency_update #47
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
# 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 }}-${{ github.sha | slice: 0, 7 }}" | ||
Check failure on line 101 in .github/workflows/ci.yml GitHub Actions / Dependency BotInvalid workflow file
|
||
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 }} |