-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (94 loc) · 4.08 KB
/
ci.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
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 }}