-
Notifications
You must be signed in to change notification settings - Fork 1
74 lines (69 loc) · 3.04 KB
/
update_submodule.yml
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
# This is a workflow for updating the external repositories contained in this repository as git submodules.
#
# It is configured to be triggered by repository dispatch events which come from outside of this repository.
# It requires write access to the repository by providing a personal access token (PAT) with `repo` scope.
#
# The `event_type` parameter is expected to be `trigger-update-submodule`.
# The `client_payload` parameter is expected to contain the following data:
# * `repo_name`: a string containing the `phylum-dev` repository name to update
# * `tag_name`: a string containing the release tag to use for updating the git submodule
#
# Here is an example repository dispatch event, triggered with `curl` from the command line:
#
# curl \
# -X POST \
# --fail-with-body \
# -H "Accept: application/vnd.github+json" \
# -H "X-GitHub-Api-Version: 2022-11-28" \
# -H "Authorization: token <PAT>" \
# -d '{"event_type":"trigger-update-submodule","client_payload":{"repo_name":"cli","tag_name":"v6.0.1"}}' \
# https://api.github.com/repos/phylum-dev/documentation/dispatches
#
# References:
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#repository_dispatch
# https://docs.github.com/en/rest/repos/repos#create-a-repository-dispatch-event
---
name: Update Submodules
on:
repository_dispatch:
types: [trigger-update-submodule]
jobs:
bump:
name: Update submodules and create PR
runs-on: ubuntu-latest
env:
REPO_NAME: ${{ github.event.client_payload.repo_name }}
TAG_NAME: ${{ github.event.client_payload.tag_name }}
steps:
- name: Checkout the repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: true
- name: Update submodule
run: |
git -C "ext/${REPO_NAME}" fetch --all --tags
git -C "ext/${REPO_NAME}" checkout "${TAG_NAME}"
- name: Commit changes
run: |
git config user.name 'phylum-bot'
git config user.email '[email protected]'
git add "ext/${REPO_NAME}"
git commit -m "build: update \`${REPO_NAME}\` submodule to \`${TAG_NAME}\`"
git push --force origin "HEAD:update-${REPO_NAME}-submodule"
- name: Create Pull Request
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
github-token: ${{ secrets.GH_RELEASE_PAT }}
script: |
const repo = process.env.REPO_NAME;
const tag = process.env.TAG_NAME;
const response = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
head: "update-" + repo + "-submodule",
base: context.ref,
title: "build: update `" + repo + "` submodule to `" + tag + "`",
body: "This submodule update was triggered by a " + repo + " release "
+ "and ensures the documentation stays current.",
});
console.log(response);