Skip to content

Synchronizing Cloudformation repo with serverless #69

Synchronizing Cloudformation repo with serverless

Synchronizing Cloudformation repo with serverless #69

Workflow file for this run

name: Synchronizing Cloudformation repo with serverless
on:
pull_request:
types: [closed]
branches: [master, main]
paths:
- "src/**/template.*"
- "src/**/README.md"
workflow_dispatch:
inputs:
refToBuild:
description: 'commit SHA1'
required: true
type: string
jobs:
Get-matrix:
runs-on: ubuntu-latest
if: ${{ github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch' }}
outputs:
packages: ${{ env.packages }}
steps:
- uses: actions/checkout@v4
- name: Read matrix YAML
id: read-matrix
run: |
export PACKAGES=$(jq -r '.[].name' matrix.js | jq -rcnR '[inputs]')
echo "packages=$PACKAGES" >> $GITHUB_ENV
# to save a directory as an Artifact it must contain a file
- name: Create template-readme-directory
run: |
mkdir template-readme-directory
touch template-readme-directory/file.tmp
- name: Upload template-readme-directory
uses: actions/upload-artifact@v4.3.3
with:
name: template-readme-directory
path: ./template-readme-directory/
- name: Create changes file list
run: touch change_file_list.txt
- name: Upload changes file list
uses: actions/upload-artifact@v4.3.3
with:
name: change_file_list
path: change_file_list.txt
Apply-changes:
runs-on: ubuntu-latest
if: ${{ github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch' }}
needs: Get-matrix
strategy:
matrix:
package: ${{ fromJSON(needs.Get-matrix.outputs.packages) }}
max-parallel: 1
steps:
- name: checkout when trigger is from push
uses: actions/checkout@v4
if: "${{ inputs.refToBuild == null }}"
- name: checkout when trigger manually
uses: actions/checkout@v4
if: "${{ inputs.refToBuild != null }}"
with:
ref: ${{ inputs.refToBuild }}
- id: changes
uses: dorny/paths-filter@v3
if: "${{ inputs.refToBuild == null }}"
with:
filters: |
'${{ matrix.package }}':
- 'src/${{ matrix.package }}/**'
- id: changes-triger-manually
uses: dorny/paths-filter@v3
if: "${{ inputs.refToBuild != null }}"
with:
filters: |
'${{ matrix.package }}':
- 'src/${{ matrix.package }}/**'
base: ${{ inputs.refToBuild }}
ref: master
- if: ${{ steps.changes.outputs[matrix.package] == 'true' || steps.changes-triger-manually.outputs[matrix.package] == 'true' }}
name: Change template and README to CF
run: |
chmod +x scripts/replace_codeuri.sh
scripts/replace_codeuri.sh src/${{ matrix.package }}/template.* ${{ matrix.package }} src/${{ matrix.package }}/README.md
- if: ${{ steps.changes.outputs[matrix.package] == 'true' || steps.changes-triger-manually.outputs[matrix.package] == 'true' }}
name: Create template and readme directory
run: mkdir template-readme-directory
- if: ${{ steps.changes.outputs[matrix.package] == 'true' || steps.changes-triger-manually.outputs[matrix.package] == 'true' }}
name: Download template and readme artifact
uses: actions/download-artifact@v4
with:
name: template-readme-directory
path: ./template-readme-directory
- if: ${{ steps.changes.outputs[matrix.package] == 'true' || steps.changes-triger-manually.outputs[matrix.package] == 'true' }}
name: Add integration to matrix file
run: |
mv src/${{ matrix.package }}/README.md template-readme-directory/${{ matrix.package }}_README
mv src/${{ matrix.package }}/template.* template-readme-directory/${{ matrix.package }}_template.yaml
if [ -f "src/${{ matrix.package }}/CHANGELOG.md" ]; then
mv src/${{ matrix.package }}/CHANGELOG.md template-readme-directory/${{ matrix.package }}_CHANGELOG.md
fi
- if: ${{ steps.changes.outputs[matrix.package] == 'true' || steps.changes-triger-manually.outputs[matrix.package] == 'true' }}
name: Upload template-readme-directory
uses: actions/upload-artifact@v4.3.3
with:
name: template-readme-directory-${{ matrix.package }}
path: ./template-readme-directory/
- if: ${{ steps.changes.outputs[matrix.package] == 'true' || steps.changes-triger-manually.outputs[matrix.package] == 'true' }}
name: Download change_file_list
uses: actions/download-artifact@v4
with:
name: change_file_list
- if: ${{ steps.changes.outputs[matrix.package] == 'true' || steps.changes-triger-manually.outputs[matrix.package] == 'true' }}
name: Add integration to change_file_list
run: echo "${{ matrix.package }}" >> change_file_list.txt
- if: ${{ steps.changes.outputs[matrix.package] == 'true' || steps.changes-triger-manually.outputs[matrix.package] == 'true' }}
name: Upload change_file_list
uses: actions/upload-artifact@v4.3.3
with:
name: change_file_list_${{ matrix.package }}
path: change_file_list.txt
Push-changes:
needs: Apply-changes
runs-on: ubuntu-latest
steps:
- name: Checkout destination repository
uses: actions/checkout@v4
with:
repository: guyrenny/guy-renny-cloudformation
token: ${{ secrets.DESTINATION_REPO_TOKEN }}
- name: Create template-readme-directory
run: mkdir ./template-readme-directory
- name: Download template-readme-directory
uses: actions/download-artifact@v4
with:
# name: template-readme-directory
path: ./template-readme-directory
- name: Download change_file_list
uses: actions/download-artifact@v4
# with:
# name: change_file_list
- name: Commit and push chage files
run: |
echo "the file"
ls | grep change_file_list
echo "end of file"
for file in change_file_list_*; do
line="${file#change_file_list_}"
echo "The integration is:"
echo $line
if [[ -d "aws-integrations/lambda-integrations/$line" ]]; then
echo " in the if"
mv template-readme-directory-${line}/${line}_README aws-integrations/lambda-integrations/$line/README.md
mv template-readme-directory-${line}/${line}_template.yaml aws-integrations/lambda-integrations/$line/template.yaml
if [ -f "template-readme-directory-${line}/${line}_CHANGELOG.md" ]; then
mv template-readme-directory-${line}/${line}_CHANGELOG.md aws-integrations/lambda-integrations/$line/CHANGELOG.md
fi
else
echo "in the else condition"
mkdir aws-integrations/lambda-integrations/$line
mv template-readme-directory-${line}/${line}_README aws-integrations/lambda-integrations/$line/README.md
mv template-readme-directory-${line}/${line}_template.yaml aws-integrations/lambda-integrations/$line/template.yaml
if [ -f "template-readme-directory-${line}/${line}_CHANGELOG.md" ]; then
mv template-readme-directory-${line}/${line}_CHANGELOG.md aws-integrations/lambda-integrations/$line/CHANGELOG.md
fi
fi
done
rm -rf change_file_list*
rm -rf template-readme-directory*
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git checkout master
git pull
git add .
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "commit_message=sync-from-serverless" >> $GITHUB_ENV
else
echo "commit_message=${{ github.event.pull_request.title }}" >> $GITHUB_ENV
fi
- uses: planetscale/ghcommit-action@v0.1.19
with:
commit_message: ${{ env.commit_message }}
repo: guyrenny/guy-renny-cloudformation
branch: master
file_pattern: '*.yaml *.md'
env:
GITHUB_TOKEN: ${{secrets.DESTINATION_REPO_TOKEN}}