Skip to content

Commit

Permalink
Update regenerate-schema.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
SonQBChau committed Nov 29, 2023
1 parent c5fac37 commit 50d2ff6
Showing 1 changed file with 62 additions and 50 deletions.
112 changes: 62 additions & 50 deletions .github/workflows/regenerate-schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ jobs:
with:
file_pattern: 'chord_metadata_service/mohpackets/docs/schema.json'
commit_message: Regenerate schema.json

- name: Get latest commit SHA
run: echo "::set-output name=commit_sha::$(git rev-parse HEAD)"

- name: Use the commit SHA
run: echo "The latest commit SHA is ${{ steps.get_sha.outputs.commit_sha }}"

# - name: Commit and push changes to schema.json
# uses: actions/github-script@v6
Expand All @@ -46,68 +52,74 @@ jobs:

# await commitAndPushChanges('schema.json', `${{ github.head_ref }}`, fs, octokit, context);

second_job:
name: Adding schema SHA
needs: first_job
runs-on: ubuntu-latest
# second_job:
# name: Adding schema SHA
# needs: first_job
# runs-on: ubuntu-latest

steps:
- name: Check out repo
uses: actions/checkout@v4
# steps:
# - name: Check out repo
# uses: actions/checkout@v4

- name: Git pull to update the repository
run: git pull origin ${{ github.head_ref }}
# - name: Git pull to update the repository
# run: git pull origin ${{ github.head_ref }}

- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "3.12"
# - name: Install Python
# uses: actions/setup-python@v4
# with:
# python-version: "3.12"

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18
# - name: Set up Node.js
# uses: actions/setup-node@v4
# with:
# node-version: 18

- name: Create package.json file
run: |
echo '{"name": "my-project", "version": "1.0.0"}' > package.json
# - name: Create package.json file
# run: |
# echo '{"name": "my-project", "version": "1.0.0"}' > package.json

- name: Install npm
run: npm install
# - name: Install npm
# run: npm install

- name: Install widdershins
run: npm install -g widdershins
# - name: Install widdershins
# run: npm install -g widdershins

- name: Install PyYAML
run: pip install PyYAML
# - name: Install PyYAML
# run: pip install PyYAML

- name: Convert schema to OpenAPI documentation
run: |
npx widdershins ./chord_metadata_service/mohpackets/docs/schema.json -o ./chord_metadata_service/mohpackets/docs/schema.md -u ./chord_metadata_service/mohpackets/docs/widdershins/templates/openapi3 -c true --omitHeader true
# - name: Convert schema to OpenAPI documentation
# run: |
# npx widdershins ./chord_metadata_service/mohpackets/docs/schema.json -o ./chord_metadata_service/mohpackets/docs/schema.md -u ./chord_metadata_service/mohpackets/docs/widdershins/templates/openapi3 -c true --omitHeader true

- name: Convert schema.json to schema.yml
run: python -c 'import json, yaml; json.load(open("chord_metadata_service/mohpackets/docs/schema.json")); print(yaml.dump(json.load(open("chord_metadata_service/mohpackets/docs/schema.json"))))' > chord_metadata_service/mohpackets/docs/schema.yml
# - name: Convert schema.json to schema.yml
# run: python -c 'import json, yaml; json.load(open("chord_metadata_service/mohpackets/docs/schema.json")); print(yaml.dump(json.load(open("chord_metadata_service/mohpackets/docs/schema.json"))))' > chord_metadata_service/mohpackets/docs/schema.yml

- name: Update schema with last SHA
run: |
REPO_NAME=${{ github.repository }}
HEAD_REF=${{ github.head_ref }}
SHA=$(git rev-parse HEAD)
DOCS_PATH="chord_metadata_service/mohpackets/docs/"
SCHEMA_PATHS=(
"${DOCS_PATH}schema.json"
"${DOCS_PATH}schema.yml"
"${DOCS_PATH}schema.md"
)
for path in "${SCHEMA_PATHS[@]}"; do
sed -i "s|This is the RESTful API for the MoH Service.|This is the RESTful API for the MoH Service. Based on https://raw.githubusercontent.com/$REPO_NAME/$SHA/$path|" "$path"
done
# - name: Update schema with last SHA
# run: |
# REPO_NAME=${{ github.repository }}
# HEAD_REF=${{ github.head_ref }}
# SHA=$(git rev-parse HEAD)

- uses: stefanzweifel/git-auto-commit-action@v5
with:
file_pattern: 'chord_metadata_service/mohpackets/docs/schema.*'
commit_message: Update schema SHA
# DOCS_PATH="chord_metadata_service/mohpackets/docs/"
# SCHEMA_PATHS=(
# "${DOCS_PATH}schema.json"
# "${DOCS_PATH}schema.yml"
# "${DOCS_PATH}schema.md"
# )
# for path in "${SCHEMA_PATHS[@]}"; do
# sed -i "s|This is the RESTful API for the MoH Service.|This is the RESTful API for the MoH Service. Based on https://raw.githubusercontent.com/$REPO_NAME/$SHA/$path|" "$path"
# done

# - uses: stefanzweifel/git-auto-commit-action@v5
# with:
# file_pattern: 'chord_metadata_service/mohpackets/docs/schema.*'
# commit_message: Update schema SHA






# - name: Commit and push changes
# uses: actions/github-script@v6
# with:
Expand Down

0 comments on commit 50d2ff6

Please sign in to comment.