-
Notifications
You must be signed in to change notification settings - Fork 1.5k
129 lines (117 loc) · 5.1 KB
/
jan-plugins.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: Jan Default Plugins
on:
push:
branches:
- main
paths:
- "plugins/**"
- "!plugins/*/package.json"
pull_request:
branches:
- main
paths:
- "plugins/**"
- ".github/workflows/jan-plugins.yml"
- "!plugins/*/package.json"
jobs:
build:
runs-on: mac-silicon
environment: production
outputs:
branch_name: ${{ steps.commit_and_tag.outputs.branch_name }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: "0"
token: ${{ secrets.PAT_SERVICE_ACCOUNT }}
- name: Install jq
uses: dcarbone/[email protected]
- name: Check Path Change
run: |
git config --global user.email "[email protected]"
git config --global user.name "Service Account"
echo "Changes in these directories trigger the build:"
changed_dirs=$(git -c http.extraheader="AUTHORIZATION: bearer ${{ secrets.GITHUB_TOKEN }}" diff --name-only HEAD HEAD~1 | grep '^plugins/' | awk -F/ '{print $2}' | uniq)
echo $changed_dirs > /tmp/change_dir.txt
- name: "Auto Increase package Version"
run: |
cd plugins
for dir in $(cat /tmp/change_dir.txt)
do
echo "$dir"
# Extract current version
current_version=$(jq -r '.version' $dir/package.json)
# Break the version into its components
major_version=$(echo $current_version | cut -d "." -f 1)
minor_version=$(echo $current_version | cut -d "." -f 2)
patch_version=$(echo $current_version | cut -d "." -f 3)
# Increment the patch version by one
new_patch_version=$((patch_version+1))
# Construct the new version
new_version="$major_version.$minor_version.$new_patch_version"
# Replace the old version with the new version in package.json
jq --arg version "$new_version" '.version = $version' $dir/package.json > /tmp/package.json && mv /tmp/package.json $dir/package.json
# Print the new version
echo "Updated $dir package.json version to: $new_version"
done
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v3
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"
- name: Publish npm packages
run: |
cd plugins
for dir in $(cat /tmp/change_dir.txt)
do
echo $dir
cd $dir
npm install && npm run build && ../../.github/scripts/auto-sign.sh
if [[ $GITHUB_EVENT_NAME == 'push' && $GITHUB_EVENT_PULL_REQUEST_HEAD_REPO_FULL_NAME != $GITHUB_REPOSITORY ]]; then
npm publish --access public
fi
cd ..
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
DEVELOPER_ID: ${{ secrets.DEVELOPER_ID }}
APP_PATH: "."
- name: "Commit new version to main and create tag"
id: commit_and_tag
if: github.event_name == 'push' && github.event.pull_request.head.repo.full_name != github.repository
run: |
rm -rf /tmp/plugin-catalog
git clone https://${{ secrets.SERVICE_ACCOUNT_USERNAME }}:${{ secrets.PAT_SERVICE_ACCOUNT }}@github.com/janhq/plugin-catalog.git /tmp/plugin-catalog
for dir in $(cat /tmp/change_dir.txt)
do
echo "$dir"
version=$(jq -r '.version' plugins/$dir/package.json)
git config --global user.email "[email protected]"
git config --global user.name "Service Account"
git add plugins/$dir/package.json
git commit -m "${GITHUB_REPOSITORY}: Update tag build $version for $dir"
git -c http.extraheader="AUTHORIZATION: bearer ${{ secrets.PAT_SERVICE_ACCOUNT }}" push origin HEAD:main
git tag -a $dir-$version -m "${GITHUB_REPOSITORY}: Update tag build $version for $dir"
git -c http.extraheader="AUTHORIZATION: bearer ${{ secrets.PAT_SERVICE_ACCOUNT }}" push origin $dir-$version
plugin_name=$(jq -r '.name | sub("@janhq/"; "")' plugins/$dir/package.json)
cp plugins/$dir/package.json /tmp/plugin-catalog/${plugin_name}.json
done
cd /tmp/plugin-catalog
BRANCH_NAME="update-package-$(date +'%Y%m%d%H%M%S')"
git checkout -b $BRANCH_NAME
git add .
git commit -m "Update plugin catalog"
git push origin $BRANCH_NAME
cd /tmp && rm -rf /tmp/plugin-catalog
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
echo "::set-output name=branch_name::$BRANCH_NAME"
pull_request:
runs-on: ubuntu-latest
environment: production
if: github.event_name == 'push' && github.event.pull_request.head.repo.full_name != github.repository
needs: build
steps:
- run: |
gh pr create --title "Update plugin catalog" --body "Update plugin catalog" --base main --head ${{ needs.build.outputs.branch_name }} --repo janhq/plugin-catalog --reviewer louis-jan,hiento09
env:
GITHUB_TOKEN: ${{ secrets.PAT_SERVICE_ACCOUNT }}