Skip to content

Commit

Permalink
Merge pull request #60 from iamsdas/ci
Browse files Browse the repository at this point in the history
[CI] add pattern components generator workflow
  • Loading branch information
Revolyssup authored Dec 3, 2021
2 parents a432b41 + c899342 commit 0e87f63
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions .github/workflows/update-oam-defs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Meshery App Mesh Pattern Components Generator
on:
push:
branches:
- 'master'
jobs:
check_app_mesh_version:
name: Check App Mesh Version
runs-on: ubuntu-latest
outputs:
NEW_APP_MESH_VERSION: ${{ steps.glrt.outputs.release }}
EXISTS: ${{ env.EXISTS }}
steps:
- name: Get latest release tag
id: glrt
uses: pozetroninc/github-action-get-latest-release@master
with:
repository: aws/aws-app-mesh-controller-for-k8s
excludes: prerelease, draft
- name: Check out code
uses: actions/checkout@master
with:
fetch-depth: 1
- name: Check if manifests for latest release exist
run: |
if [ -d templates/oam/workloads/workloads-${{ steps.glrt.outputs.release }} ]
then
echo "EXISTS=true" > $GITHUB_ENV
else
export "EXISTS=false" > $GITHUB_ENV
fi
generator:
name: Generate and push OAM definitions
needs: [check_app_mesh_version]
if: ${{ !needs.check_app_mesh_version.outputs.EXISTS }}
env:
NEW_APP_MESH_VERSION: ${{ needs.check_app_mesh_version.outputs.NEW_APP_MESH_VERSION }}
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@master
with:
fetch-depth: 1
token: ${{ secrets.GH_ACCESS_TOKEN }}
ref: 'master'
- name: Get App Mesh manifests
run: |
mkdir ./app-mesh-crds
cd ./app-mesh-crds
curl --remote-name-all `curl -H "Accept: application/vnd.github.VERSION.raw" https://api.github.com/repos/aws/aws-app-mesh-controller-for-k8s/contents/config/crd/bases\?ref\=$NEW_APP_MESH_VERSION | jq 'map(.download_url) | .[]' | tr -d '"'`
cd ..
awk 'FNR==1 && NR>1 { printf("\n%s\n\n","---") } 1' app-mesh-crds/*.yaml > ~/app.yaml
- name: Build jsonschema util
run: |
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
nvm install v14.15.3
nvm install-latest-npm
git clone https://github.com/layer5io/kubeopenapi-jsonschema util
cd util
npm i; npm i nexe -g
make linux
- name: Generate Workload definitions
run: |
dirPath=../templates/oam/workloads/workloads-$NEW_APP_MESH_VERSION
cd util
mkdir -p $dirPath
meshName=appmesh
smpMeshName=APP_MESH
template='{"apiVersion":"core.oam.dev/v1alpha1","kind":"WorkloadDefinition","metadata":{},"spec":{"definitionRef":{},"metadata":{"@type":"pattern.meshery.io/mesh/workload","meshVersion":"'$NEW_APP_MESH_VERSION'","meshName":"'$smpMeshName'","k8sAPIVersion":null,"k8sKind":""}}}'
crds=$(./kubeopenapi-jsonschema --location ~/app.yaml -t yaml --filter '$[?(@.kind=="CustomResourceDefinition")]' -o json --o-filter '$..["spec"]["names"]["kind"]' | jq '.[]')
for t in ${crds[@]}; do
nameUpper=`echo $t | tr -d '"'`
nameLower=`echo $t | tr -d '"' | tr '[:upper:]' '[:lower:]'`
definitionRef=$(printf %s.appmesh.meshery.layer5.io $nameLower)
apiVersion=$(./kubeopenapi-jsonschema --location ~/app.yaml -t yaml --filter '$[?(@.kind=="CustomResourceDefinition" && @.spec.names.kind=='$t')]..spec.versions[0]' --o-filter "$[].name" -o json | jq '.[]' | tr -d '"')
apiGroup=$(./kubeopenapi-jsonschema --location ~/app.yaml -t yaml --filter '$[?(@.kind=="CustomResourceDefinition" && @.spec.names.kind=='$t')]..spec' --o-filter "$[].group" -o json | jq '.[]' | tr -d '"')
./kubeopenapi-jsonschema --location ~/app.yaml -t yaml --filter '$[?(@.kind=="CustomResourceDefinition" && @.spec.names.kind=='$t')]..openAPIV3Schema.properties.spec' --o-filter "$[]" -o json |\
jq '.[]' > $dirPath/$nameLower.appmesh.meshery.layer5io.schema.json
echo $template |\
jq '
."metadata"."name" = "'$(printf %s.APP_MESH $nameUpper)'"
| ."spec"."metadata"."k8sAPIVersion" = "'$(printf $apiGroup/$apiVersion $apiGroup $apiVersion)'"
| ."spec"."metadata"."k8sKind" = "'$nameUpper'"
| ."spec"."definitionRef"."name"="'$definitionRef'"' > $dirPath/$nameLower.appmesh_definition.json
done
- name: Cleanup
run: |
rm -rf util
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
file_pattern: templates/
commit_user_name: l5io
commit_user_email: [email protected]
commit_author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
commit_options: '--signoff'
commit_message: '[Patterns] Pattern components generated from latest App Mesh manifests'
branch: master

0 comments on commit 0e87f63

Please sign in to comment.