Skip to content

Commit 062d945

Browse files
committed
[WIP]: new-plugin CI workflow
1 parent 2e3083e commit 062d945

File tree

1 file changed

+149
-0
lines changed

1 file changed

+149
-0
lines changed

.github/workflows/new-plugin.yml

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
name: new-plugin
2+
on:
3+
push:
4+
branch:
5+
- "main"
6+
paths:
7+
- "plugins/**"
8+
9+
# Prevent running this workflow concurrently
10+
concurrency:
11+
group: "matrix-messages"
12+
13+
jobs:
14+
setup:
15+
name: Collect metadata and setup job matrix
16+
runs-on: ubuntu-latest
17+
timeout-minutes: 40
18+
if: github.repository == 'nix-community/nixvim'
19+
20+
outputs:
21+
plugins: ${{ steps.get_info.outputs.json }}
22+
pr_number: ${{ steps.pr.outputs.number }}
23+
pr_url: ${{ steps.get_pr.outputs.url }}
24+
pr_author_name: ${{ steps.get_pr.outputs.author_name }}
25+
pr_author_url: ${{ steps.get_pr.outputs.author_url }}
26+
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
31+
- name: Install Nix
32+
uses: cachix/install-nix-action@v26
33+
with:
34+
nix_path: nixpkgs=channel:nixos-unstable
35+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Get plugins info
38+
id: get_info
39+
run: |
40+
# Use `nix eval` to get json arrays containing plugins available on the pushed commit, and the previous commit
41+
OLD_PLUGINS=$(
42+
nix eval 'github:${{ github.repository }}/${{ github.event.before }}#nixvimConfiguration.options.plugins' \
43+
--apply 'builtins.attrNames' \
44+
--json
45+
)
46+
NEW_PLUGINS=$(
47+
nix eval '.#nixvimConfiguration.options.plugins' \
48+
--apply 'builtins.attrNames' \
49+
--json
50+
)
51+
OLD_COLORSCHEMES=$(
52+
nix eval 'github:${{ github.repository }}/${{ github.event.before }}#nixvimConfiguration.options.colorschemes' \
53+
--apply 'builtins.attrNames' \
54+
--json
55+
)
56+
NEW_COLORSCHEMES=$(
57+
nix eval '.#nixvimConfiguration.options.colorschemes' \
58+
--apply 'builtins.attrNames' \
59+
--json
60+
)
61+
PLUGIN_JSON="{ \"old\": $OLD_PLUGINS, \"new\": $NEW_PLUGINS }"
62+
COLORSCHEME_JSON="{ \"old\": $OLD_COLORSCHEMES, \"new\": $NEW_COLORSCHEMES }"
63+
64+
# Collect added/removed plugins by subtracting old/new arrays
65+
GROUPED="{
66+
\"added\": {
67+
\"plugin\": $(echo "$PLUGIN_JSON" | jq '.new-.old'),
68+
\"colorscheme\": $(echo "$COLORSCHEME_JSON" | jq '.new-.old')
69+
},
70+
\"removed\": {
71+
\"plugin\": $(echo "$PLUGIN_JSON" | jq '.old-.new'),
72+
\"colorscheme\": $(echo "$COLORSCHEME_JSON" | jq '.old-.new')
73+
}
74+
}"
75+
76+
# Un-group types to `{ "added": [ { "type": "plugin", "name": "foo" } ], "removed": [] }`
77+
GROUPED_BY_CHANGE=$(echo "$GROUPED" | jq -c 'map_values(to_entries | map(.key as $type | .value[] | { type: $type, name: . }))')
78+
# TODO: When plugins are removed, try to detect renames heuristically
79+
80+
# Write to GITHUB_OUTPUT
81+
JSON=$(echo "$GROUPED_BY_CHANGE" | jq -c 'to_entries | map(.key as $change | .value[] | . += { change: $change })')
82+
echo "json=$JSON" >> $GITHUB_OUTPUT
83+
84+
- name: Get PR info
85+
id: get_pr
86+
if: steps.get_info.outputs.json != '[]'
87+
env:
88+
GH_TOKEN: ${{ github.token }}
89+
run: |
90+
# `gh` will have already printed to stderr, so no need to parse the response json
91+
JSON=$(
92+
gh api \
93+
-H "Accept: application/vnd.github+json" \
94+
-H "X-GitHub-Api-Version: 2022-11-28" \
95+
/repos/${{ github.repository }}/commits/${{ github.sha }}/pulls
96+
) || exit 1
97+
98+
if [[ "$(echo "$JSON" | jq -c '.')" = "[]" ]]; then
99+
# No associated PR
100+
# TODO: does this need special handling?
101+
else
102+
# Print key=value pairs to GITHUB_OUTPUT
103+
echo "$JSON" | \
104+
jq -r '.[0] | { number: .number, url: .html_url, author_name: .user.login, author_url: .user.html_url } | to_entries[] | "\(.key)=\(.value)"' \
105+
>> $GITHUB_OUTPUT
106+
fi
107+
108+
send:
109+
name: Send matrix message
110+
runs-on: ubuntu-latest
111+
needs: setup
112+
strategy:
113+
matrix:
114+
plugins: ${{ fromJSON(needs.setup.outputs.plugins) }}
115+
env:
116+
name: ${{ matrix.plugins.name }}
117+
type: ${{ matrix.plugins.type }}
118+
change: ${{ matrix.plugins.change }}
119+
pr_number: ${{ needs.setup.outputs.pr_number }}
120+
pr_url: ${{ needs.setupt_pr.outputs.pr_url }}
121+
pr_author_name: ${{ needs.setupt_pr.outputs.pr_author_name }}
122+
pr_author_url: ${{ needs.setupt_pr.outputs.pr_author_url }}
123+
124+
steps:
125+
- name: Install matrix-msg tool
126+
uses: lkiesow/matrix-notification@v1
127+
with:
128+
token: ${{ secrets.CI_MATRIX_TOKEN }}
129+
server: ${{ secrets.CI_MATRIX_SERVER }}
130+
room: ${{ secrets.CI_MATRIX_ROOM }}
131+
tool: true
132+
133+
- name: Send message and print summary
134+
run: |
135+
# Message text; plain-text & html
136+
# TODO: format as-per existing announcements
137+
# See available env-vars above
138+
msg="Hello, world!"
139+
html_msg="Hello, <b>world!</b>"
140+
141+
# stdout
142+
echo "$msg"
143+
144+
# markdown summary
145+
echo "$html_msg" >> $GITHUG_STEP_SUMMARY
146+
147+
# matrix message
148+
matrix-msg "$msg" "$html_msg"
149+
# TODO: update stdout/step_summary with msg success/failure

0 commit comments

Comments
 (0)