Skip to content

Commit

Permalink
ci: add org parameter and adding files
Browse files Browse the repository at this point in the history
  • Loading branch information
aprilselby88 committed Nov 3, 2023
1 parent c6278b8 commit 98156ca
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 4 deletions.
76 changes: 76 additions & 0 deletions .github/addingFile/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: 'addingFiles'

description: 'Adds files to git'

inputs:
files:
description: File or folder to add
required: true
commit-message:
description: Commit message when raising pr
default: "chore: adding files"
required: false
branch-name:
description: Branch name when raising pr
default: chore/add-files
required: false
title:
description: Title of raised pr
default: 'chore: adding files'
required: false
body:
description: Body of raised pr
default: Adding files
required: false
labels:
description: Lavels for pr (separated by new line)
default: automated pr
required: false
token:
description: Access token to push and raise pr
required: true


runs:
using: 'composite'
steps:
- name: Checkout scaffolder repo
uses: actions/checkout@v4
- name: Check file or folder exists
run: |
${{ github.action_path }}/lintInput.sh ${{ inputs.files }}
shell: bash
- name: Checkout target repository
uses: actions/checkout@v4
with:
repository: ${{ inputs.repository }}
ref: main
fetch-depth: 0
token: ${{ inputs.token }}
- name: Configure git
run: |
git config user.name 'Github Action'
git config user.email '[email protected]'
- name: Checkout branch and copy over files
run: |
git checkout -b ${{ inputs.branch-name }}
cd .
ls
cp -R /home/runner/work/repo-scaffolder/${{ inputs.files }} /home/runner/work/${{ inputs.repository }}/
cd /home/runner/work/${{ inputs.repository }}/
ls
- name: Add to git
run: |
git add ${{ inputs.files }}
- name: Create pull request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ inputs.token }}
commit-message: ${{ inputs.commit-message }}
branch: ${{ inputs.branch-name }}
delete-branch: true
title: ${{ inputs.title }}
body: |
${{ inputs.body }}
labels: |
${{ inputs.labels }}
11 changes: 11 additions & 0 deletions .github/addingFile/lintInput.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

location=$1

if test -f $location; then
echo "File exists."
elif test -d $location; then
echo "Directory exists."
else
echo "error: file or direcoty not found: " $1 >&2; exit 1
fi
2 changes: 1 addition & 1 deletion .github/fileUpdater/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ runs:
repository: ${{ inputs.repository }}
token: ${{ inputs.token }}
- name: Update files
run: ${{ github.action_path }}/update.sh ${{ inputs.find }} ${{ inputs.replace }} ${{ inputs.file }}
run: ${{ github.action_path }}/update.sh ${{ inputs.find }} ${{ inputs.replace }} ${{ inputs.filename }}
shell: bash
- name: Create pull request
uses: peter-evans/create-pull-request@v5
Expand Down
5 changes: 4 additions & 1 deletion .github/findRepos/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ inputs:
query:
description: Query for github api (for example topic:xyz)
required: true
org:
description: Org to search for repos in (for example DSACMS)
required: true
token:
description: Token to query github api
required: true
Expand All @@ -17,7 +20,7 @@ runs:
uses: actions/checkout@v4
- name: Query Github Api
run: |
repos=$(${{ github.action_path }}/find.sh ${{ inputs.query }} ${{ inputs.token }})
repos=$(${{ github.action_path }}/find.sh ${{ inputs.query }} ${{ input.org }} ${{ inputs.token }})
echo $repos
echo "repo="$repos"" >> $GITHUB_ENV
shell: bash
5 changes: 3 additions & 2 deletions .github/findRepos/find.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/bin/bash

query=$1
token=$2
org=$2
token=$3

curl -s -H "Authorization: token $token" GET https://api.github.com/search/repositories?q=org:DSACMS+$query >> apiJson.json
curl -s -H "Authorization: token $token" GET https://api.github.com/search/repositories?q=org:$org+$query >> apiJson.json
total_count=$(jq '.total_count' apiJson.json)
if [ -z "$total_count" ]; then
cat apiJson.json
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/addFilesToRepos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Add files to repos

on:
workflow_dispatch:
inputs:
query:
description: 'Query for github API'
default: 'topic:x'
required: true
org:
description: 'Org to search for repos in'
default: 'DSACMS'
required: true
files:
description: 'File or folders to add'
default: 'tier1/LICENSE'
required: true

env:
repo: ""

jobs:
find-repos:
runs-on: ubuntu-latest
name: Find repos and generate matrix
steps:
- name: Checkout Action
uses: actions/checkout@v4
- name: Find repos
uses: ./.github/findRepos
with:
query: ${{ github.event.inputs.query }}
org: ${{ github.event.inputs.org }}
token: ${{ secrets.pat }}
outputs:
matrix: ${{ env.repo }}

add-files:
runs-on: ubuntu-latest
name: Add files
needs: [find-repos]
strategy:
matrix:
repo: ${{ fromJSON(needs.find-repos.outputs.matrix ) }}
steps:
- name: Checkout Action
uses: actions/checkout@v4
- name: Update file
uses: ./.github/addingFile
with:
repository: ${{ matrix.repo }}
files: ${{ github.event.inputs.files }}
token: ${{ secrets.pat }}
5 changes: 5 additions & 0 deletions .github/workflows/updateStringInRepos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ on:
description: 'Query from github API'
default: 'topic:x'
required: true
org:
description: 'Org to search for repos in'
default: 'DSACMS'
required: true
find:
description: 'String to search for'
default: 'x'
Expand All @@ -33,6 +37,7 @@ jobs:
uses: ./.github/findRepos
with:
query: ${{ github.event.inputs.query }}
org: ${{ github.event.inputs.org }}
token: ${{ secrets.pat }}
outputs:
matrix: ${{ env.repo }}
Expand Down

0 comments on commit 98156ca

Please sign in to comment.