-
Notifications
You must be signed in to change notification settings - Fork 12
85 lines (72 loc) · 3.08 KB
/
Copy pathrelease-notes-sync.yaml
File metadata and controls
85 lines (72 loc) · 3.08 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
name: "Release notes sync"
on:
workflow_dispatch:
schedule:
- cron: "0 6 * * 1"
permissions:
contents: read
jobs:
sync-release-notes:
name: "Sync release notes"
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: "Generate GitHub App token"
id: app-token
uses: actions/create-github-app-token@v3.2.0
with:
client-id: "${{ secrets.APP_CLIENT_ID }}"
private-key: "${{ secrets.APP_PEM_FILE }}"
- name: "Checkout code"
uses: actions/checkout@v4
- name: "Update release notes data"
uses: ./.github/actions/release-notes
env:
JIRA_TOKEN: "${{ secrets.JIRA_TOKEN }}"
JIRA_BASE_URL: "${{ secrets.JIRA_URL }}/rest/api/2"
- name: "Detect release notes changes"
id: changes
shell: bash
run: |
if git diff --quiet -- docs/_data/release-notes.json; then
echo "has_changes=false" >> "$GITHUB_OUTPUT"
else
echo "has_changes=true" >> "$GITHUB_OUTPUT"
fi
- name: "Commit and raise pull request"
if: steps.changes.outputs.has_changes == 'true'
env:
GH_TOKEN: "${{ steps.app-token.outputs.token }}"
shell: bash
run: |
DEFAULT_SHA=$(gh api "repos/$GITHUB_REPOSITORY/git/ref/heads/main" --jq '.object.sha')
# Create branch pointing to main, or force-reset it if it already exists
gh api --method POST "repos/$GITHUB_REPOSITORY/git/refs" \
-f ref="refs/heads/automation/release-notes-cache" \
-f sha="$DEFAULT_SHA" 2>/dev/null || \
gh api --method PATCH "repos/$GITHUB_REPOSITORY/git/refs/heads/automation/release-notes-cache" \
-f sha="$DEFAULT_SHA" \
-F force=true
# Commits via the Contents API are automatically verified by GitHub
FILE_SHA=$(gh api "repos/$GITHUB_REPOSITORY/contents/docs/_data/release-notes.json?ref=automation/release-notes-cache" --jq '.sha' 2>/dev/null || echo "")
FILE_CONTENT=$(base64 -w 0 docs/_data/release-notes.json)
if [ -n "$FILE_SHA" ]; then
gh api --method PUT "repos/$GITHUB_REPOSITORY/contents/docs/_data/release-notes.json" \
-f message="sync release notes" \
-f content="$FILE_CONTENT" \
-f sha="$FILE_SHA" \
-f branch="automation/release-notes-cache"
else
gh api --method PUT "repos/$GITHUB_REPOSITORY/contents/docs/_data/release-notes.json" \
-f message="sync release notes" \
-f content="$FILE_CONTENT" \
-f branch="automation/release-notes-cache"
fi
gh pr create \
--title "CCM-18043: Sync release notes" \
--body "## Summary
This PR syncs the release notes generated from JIRA for the last year.
- Trigger: \`${{ github.event_name }}\`
- Source: \`JIRA_URL secret (expanded to REST API base path)\`" \
--base main \
--head automation/release-notes-cache 2>/dev/null || echo "PR already exists"