-
Notifications
You must be signed in to change notification settings - Fork 7
103 lines (87 loc) · 3.6 KB
/
publish_docs_update.yml
File metadata and controls
103 lines (87 loc) · 3.6 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
name: Update OpenSearch Dashboards docs submodule
on:
push:
branches:
- 2/edge
paths:
- 'docs/**'
workflow_dispatch:
jobs:
update-docs-submodule:
name: Open PR to update OpenSearch Dashboards docs submodule
runs-on: ubuntu-latest
env:
BASE_BRANCH: 2/edge
PR_BRANCH: auto/update-dashboards-docs-submodule-${{ github.sha }}
# Path to the submodule inside the opensearch-operator repository
SUBMODULE_PATH: docs/dashboards
steps:
- name: Checkout target repository
uses: actions/checkout@v6
with:
repository: canonical/opensearch-operator
ref: ${{ env.BASE_BRANCH }}
token: ${{ secrets.PAT }}
submodules: true
path: target-repo
- name: Get reviewers
id: get-reviewers
working-directory: target-repo
run: |
REVIEWERS=""
if [[ -f .github/CODEOWNERS ]]; then
REVIEWERS=$(grep "${SUBMODULE_PATH}" .github/CODEOWNERS \
| awk '{for(i=2;i<=NF;i++) print substr($i,2)}' \
| paste -sd "," -)
fi
echo "REVIEWERS=${REVIEWERS}" >> "$GITHUB_OUTPUT"
- name: Configure git signing
working-directory: target-repo
run: |
mkdir -p ~/.ssh
echo "${{ secrets.CI_COMMITS_SSH_SIGNING_KEY }}" > ~/.ssh/ssh-key
chmod 600 ~/.ssh/ssh-key
git config --global user.name "canonical-data-platform-bot"
git config --global user.email "canonical-data-platform-bot@canonical.com"
git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/ssh-key
git config --global commit.gpgsign true
- name: Update submodule to latest commit
working-directory: target-repo
run: |
cd "${SUBMODULE_PATH}"
git fetch --depth=1 origin ${{ github.sha }}
git checkout ${{ github.sha }}
cd ../..
git add "${SUBMODULE_PATH}"
- name: Commit changes
working-directory: target-repo
run: |
if git ls-remote --exit-code --heads origin "${PR_BRANCH}" >/dev/null 2>&1; then
echo "ERROR: Branch '${PR_BRANCH}' already exists on remote. Refusing to overwrite it."
exit 1
fi
git checkout -b "${PR_BRANCH}"
git commit -m "chore: Update OpenSearch Dashboards docs submodule to ${{ github.sha }}"
- name: Push branch
working-directory: target-repo
run: |
git push origin "${PR_BRANCH}"
- name: Open Pull Request
working-directory: target-repo
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
run: |
BODY="Automated update of the OpenSearch Dashboards docs submodule to commit [\`${{ github.sha }}\`](https://github.com/canonical/opensearch-dashboards-operator/commit/${{ github.sha }})."
REVIEWER_ARGS=()
if [[ -n "${{ steps.get-reviewers.outputs.REVIEWERS }}" ]]; then
REVIEWER_ARGS=(--reviewer "${{ steps.get-reviewers.outputs.REVIEWERS }}")
fi
PR_URL=$(gh pr create \
--title "chore: Update OpenSearch Dashboards docs submodule" \
--body "${BODY}" \
--base "${{ env.BASE_BRANCH }}" \
--head "${PR_BRANCH}" \
"${REVIEWER_ARGS[@]}"
)
echo "- ${PR_URL}" >> "$GITHUB_STEP_SUMMARY"