Skip to content

Update API

Update API #931

Workflow file for this run

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@v7
- 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
response_file="${{ steps.ai.outputs.response-file }}"
echo "AI changelog response:"
cat "$response_file" || true
# Copilot CLI's response file may include narration/thinking lines
# before the final JSON answer, so grab the last line that looks
# like a JSON object rather than trying to parse the whole file.
json_line="$(grep -E '^\{.*\}$' "$response_file" 2>/dev/null | tail -n 1)"
if [ -z "$json_line" ]; then
echo "::error::AI changelog response did not contain a JSON object, see response above."
exit 1
fi
entries="$(printf '%s' "$json_line" | jq -r '.entries[]? // empty')"
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