Skip to content

Commit 3e12d66

Browse files
authored
Merge pull request #9 from DSACMS/ci/update-tagged-repos
ci: update tagged repos
2 parents d581bb6 + d5d7457 commit 3e12d66

File tree

5 files changed

+174
-0
lines changed

5 files changed

+174
-0
lines changed

.github/fileUpdater/action.yml

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: 'Update'
2+
3+
description: 'Update strings'
4+
5+
inputs:
6+
find:
7+
description: String to replace
8+
required: true
9+
replace:
10+
description: Replacement string
11+
required: true
12+
repository:
13+
description: Repository to update
14+
required: true
15+
file:
16+
description: File to replace in
17+
required: true
18+
commit-message:
19+
description: Commit message when raising pr
20+
default: "chore: updated string"
21+
required: false
22+
branch-name:
23+
description: Branch name when raising pr
24+
default: chore/update-string
25+
required: false
26+
title:
27+
description: Title of raised pr
28+
default: 'chore: updated string'
29+
required: false
30+
body:
31+
description: Body of raised pr
32+
default: Updated string
33+
required: false
34+
labels:
35+
description: Lavels for pr (separated by new line)
36+
default: automated pr
37+
required: false
38+
token:
39+
description: Access token to push and raise pr
40+
required: true
41+
42+
runs:
43+
using: 'composite'
44+
steps:
45+
- name: Checkout repository
46+
uses: actions/checkout@v4
47+
with:
48+
repository: ${{ inputs.repository }}
49+
token: ${{ inputs.token }}
50+
- name: Update files
51+
run: ${{ github.action_path }}/update.sh ${{ inputs.find }} ${{ inputs.replace }} ${{ inputs.filename }}
52+
shell: bash
53+
- name: Create pull request
54+
uses: peter-evans/create-pull-request@v5
55+
with:
56+
token: ${{ inputs.token }}
57+
commit-message: ${{ inputs.commit-message }}
58+
branch: ${{ inputs.branch-name }}
59+
delete-branch: true
60+
title: ${{ inputs.title }}
61+
body: |
62+
${{ inputs.body }}
63+
labels: |
64+
${{ inputs.labels }}

.github/fileUpdater/update.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
filename=$3
4+
search=$1
5+
replace=$2
6+
7+
sed -i -e "s/$search/$replace/g" $filename

.github/findRepos/action.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: 'githubApiFindRepos'
2+
3+
description: 'Returns list of repos from github api given a query'
4+
5+
inputs:
6+
query:
7+
description: Query for github api (for example topic:xyz)
8+
required: true
9+
token:
10+
description: Token to query github api
11+
required: true
12+
13+
runs:
14+
using: 'composite'
15+
steps:
16+
- name: Checkout Action
17+
uses: actions/checkout@v4
18+
- name: Query Github Api
19+
run: |
20+
repos=$(${{ github.action_path }}/find.sh ${{ inputs.query }} ${{ inputs.token }})
21+
echo $repos
22+
repo="${{ github.event.inputs.repo }}"
23+
echo "repo=$repos" >> $GITHUB_ENV
24+
shell: bash

.github/findRepos/find.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
query=$1
4+
token=$2
5+
6+
curl -s -H "Authorization: token $token" GET https://api.github.com/search/repositories?q=org:DSACMS+$query >> apiJson.json
7+
total_count=$(jq '.total_count' apiJson.json)
8+
echo $total_count
9+
if [ -z "$total_count" ]; then
10+
cat apiJson.json
11+
echo "error: Error fetching from github api" >&2; exit 1
12+
fi
13+
if [ "$total_count" -eq "0" ]; then
14+
cat apiJson.json
15+
echo "error: no repos found for topic" >&2; exit 1
16+
fi
17+
18+
repoStr=$(jq '.items' apiJson.json | jq '.[0].full_name')
19+
repoStr="$repoStr"
20+
output=["$repoStr"]
21+
for (( i=1; i<=$total_count-1; i++)); do
22+
repo=$(jq '.items' apiJson.json | jq '.['$i'].full_name')
23+
output=$(echo $output | jq --argjson r $repo '. + [$r]')
24+
done
25+
26+
echo $output
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Update string
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
query:
7+
description: 'Query from github API'
8+
default: 'topic:x'
9+
required: true
10+
find:
11+
description: 'String to search for'
12+
default: 'x'
13+
required: true
14+
replace:
15+
description: 'Replacement string'
16+
default: 'y'
17+
required: true
18+
file:
19+
description: 'File to replace in'
20+
default: 'CONTRIBUTING.md'
21+
22+
env:
23+
repo: ""
24+
25+
jobs:
26+
find-repos:
27+
runs-on: ubuntu-latest
28+
name: Find repos and generate matrix
29+
steps:
30+
- name: Find repos
31+
uses: ./findRepos
32+
with:
33+
query: ${{ github.event.inputs.query }}
34+
token: ${{ secrets.pat }}
35+
outputs:
36+
matrix: ${{ env.repo }}
37+
38+
update:
39+
runs-on: ubuntu-latest
40+
name: Update file
41+
needs: [find-repos]
42+
strategy:
43+
matrix:
44+
repo: ${{ fromJSON(needs.find-repos.outputs.matrix ) }}
45+
steps:
46+
- name: Update file
47+
uses: ./fileUpdater
48+
with:
49+
repository: ${{ matrix.repo }}
50+
find: ${{ github.event.inputs.find }}
51+
replace: ${{ github.event.inputs.replace }}
52+
file: ${{ github.event.inputs.file }}
53+
token: ${{ secrets.pat }}

0 commit comments

Comments
 (0)