Skip to content

Deploy GitHub Action workflow for CodeMap Generation #4

Deploy GitHub Action workflow for CodeMap Generation

Deploy GitHub Action workflow for CodeMap Generation #4

name: Generate and Deploy Codemap
on:
push:
branches:
- main
- master
- develop
- feature/* # THIS SHOULD BE ELEGANTLY HANDLED IN THE CODEBASE LATER
workflow_dispatch: # Allows manual triggering of the workflow
jobs:
deploy:
runs-on: ubuntu-latest
steps:
# Step 1: Check out the repository
- name: Checkout Repository
uses: actions/checkout@v2
# Step 2: Set up Node.js
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
# Step 3: Install the sprungg-code-mapper package
- name: Install sprungg-code-mapper
run: |
npm install @sprungg/code-mapper
# Step 4: Generate Codemap data using sprungg-code-mapper CLI
- name: Generate Codemap Data
run: |
# Generate data and save it to mapper-output.json
npx @sprungg/code-mapper . json mapper-output.json
- name: Print JSON output for debugging
run: |
cat mapper-output.json
- name: Deploy data to API
env:
SPRUNGG_API_URL: ${{ secrets.SPRUNGG_CODE_MAP_BASE_URL }} # Secure API URL
SPRUNGG_API_KEY: ${{ secrets.SPRUNGG_CODE_MAP_API_KEY }} # Secure API key for authentication
REPO_URL: ${{ secrets.SPRUNGG_CODE_MAP_REPO_URL }} # Repository URL for Sprungg reference
run: |
# Prepare the JSON payload with properly quoted file content
json_content=$(cat mapper-output.json)
json_content=$(echo "$json_content" | jq -Rs '.') # Ensure json_content is a valid JSON string
echo "JSON Content: $json_content"
curl -X POST -H "Content-Type: application/json" \
-H "Authorization: Bearer $SPRUNGG_API_KEY" \
-d '{"repoUrl": "'"$REPO_URL"'", "codemapData": '"$json_content"'}' \
"$SPRUNGG_API_URL"
# Step 6: Clean up generated file
- name: Clean up generated files
run: |
rm -f mapper-output.json