-
-
Notifications
You must be signed in to change notification settings - Fork 223
148 lines (143 loc) · 5.78 KB
/
Copy pathupdate_api.yml
File metadata and controls
148 lines (143 loc) · 5.78 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: Update API
on:
workflow_dispatch:
schedule:
- cron: "15 23 * * 1"
jobs:
update-api:
if: ${{ github.repository == 'slack-ruby/slack-ruby-client' }}
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v7
with:
submodules: recursive
fetch-depth: 0
- name: Config git to rebase
run: git config --global pull.rebase true
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.2"
bundler-cache: true
- name: Update API from slack-api-ref
run: bundle exec rake slack:api:update
- name: Remove files added by setup-ruby
run: rm -rf vendor
- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
- name: Get slack-api-ref ref
id: api-ref
run: echo "api-ref=$(git rev-parse --short HEAD:lib/slack/web/api/slack-api-ref)" >> $GITHUB_OUTPUT
- name: Check for changes
id: changes
run: |
if git diff --quiet; then
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
- name: Prepare diff for AI summary
if: steps.changes.outputs.changed == 'true'
run: |
git diff --stat | sed 's/^/ /' > /tmp/diff_stat.txt
git diff | head -c 20000 | sed 's/^/ /' > /tmp/diff.txt
- name: Set up Node
if: steps.changes.outputs.changed == 'true'
uses: actions/setup-node@v6
- name: Install Copilot CLI
if: steps.changes.outputs.changed == 'true'
run: npm install -g @github/copilot
- name: Generate changelog entries with AI
if: steps.changes.outputs.changed == 'true'
id: ai
uses: actions/ai-inference@v3
with:
prompt-file: ./.github/prompts/changelog-entries.prompt.yml
model: ''
file_input: |
diff_stat: /tmp/diff_stat.txt
diff: /tmp/diff.txt
env:
COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_PAT }}
- name: Build changelog entries
id: entries
run: |
entries=""
if [ "${{ steps.changes.outputs.changed }}" = "true" ]; then
entries="$(grep -v '^```' "${{ steps.ai.outputs.response-file }}" 2>/dev/null | jq -r '.entries[]? // empty' 2>/dev/null)"
fi
if [ -z "$entries" ]; then
entries="Update API from slack-api-ref@${{ steps.api-ref.outputs.api-ref }}"
fi
body_list="$(printf '%s\n' "$entries" | sed 's/^/- /')"
{
echo 'entries<<CHANGELOG_ENTRIES_EOF'
echo "$entries"
echo 'CHANGELOG_ENTRIES_EOF'
echo 'body_list<<CHANGELOG_BODY_EOF'
echo "$body_list"
echo 'CHANGELOG_BODY_EOF'
} >> "$GITHUB_OUTPUT"
- name: GitHub App token
if: ${{ github.repository == 'slack-ruby/slack-ruby-client' }}
id: github_app_token
uses: tibdex/github-app-token@v2.1.0
with:
app_id: ${{ secrets.CI_APP_ID }}
private_key: ${{ secrets.CI_APP_PRIVATE_KEY }}
installation_retrieval_mode: id
installation_retrieval_payload: 36985419
- name: Create pull request
id: cpr
uses: peter-evans/create-pull-request@v8
with:
token: ${{ steps.github_app_token.outputs.token || secrets.GITHUB_TOKEN }}
commit-message: |
Update API from slack-api-ref@${{ steps.api-ref.outputs.api-ref }} (${{ steps.date.outputs.date }})
${{ steps.entries.outputs.body_list }}
title: Update API from slack-api-ref@${{ steps.api-ref.outputs.api-ref }}
body: |
Update API from [slack-api-ref](https://github.com/slack-ruby/slack-api-ref).
Rev: ${{ steps.api-ref.outputs.api-ref }}
Date: ${{ steps.date.outputs.date }}
## Changes
${{ steps.entries.outputs.body_list }}
branch: automated-api-update
base: master
committer: slack-ruby-ci-bot <noreply@github.com>
author: slack-ruby-ci-bot <noreply@github.com>
- name: Check out update branch
if: ${{ steps.cpr.outputs.pull-request-number != '' }}
run: |
git fetch origin automated-api-update
git checkout automated-api-update
- name: Update CHANGELOG
if: ${{ steps.cpr.outputs.pull-request-number != '' }}
env:
PR_NUMBER: ${{ steps.cpr.outputs.pull-request-number }}
ENTRIES: ${{ steps.entries.outputs.entries }}
run: |
ruby - <<'RUBYEOF'
pr_number = ENV.fetch("PR_NUMBER")
pr_url = "https://github.com/slack-ruby/slack-ruby-client/pull/#{pr_number}"
entries = ENV.fetch("ENTRIES").each_line.map(&:strip).reject(&:empty?)
lines = entries.map do |entry|
"* [##{pr_number}](#{pr_url}): #{entry} - [@slack-ruby-ci-bot](https://github.com/apps/slack-ruby-ci-bot)."
end.join("\n")
content = File.read("CHANGELOG.md")
content = content.sub("* Your contribution here.", "#{lines}\n* Your contribution here.")
File.write("CHANGELOG.md", content)
RUBYEOF
- name: Commit and Push
if: ${{ steps.cpr.outputs.pull-request-number != '' }}
run: |
git config --local user.name 'slack-ruby-ci-bot'
git config --local user.email 'noreply@github.com'
git add CHANGELOG.md
git commit --amend --no-edit
git remote set-url origin https://x-access-token:${{ steps.github_app_token.outputs.token || secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
git push origin automated-api-update -f