Publish Postman Collection & Environment #22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish Postman Collection & Environment | |
| on: | |
| release: | |
| types: [published] | |
| workflow_run: | |
| workflows: ["Generate a Release from a Tag"] | |
| types: | |
| - completed | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| if: | | |
| github.event_name == 'release' || | |
| (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.x' | |
| - name: Install Python dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install requests | |
| - name: Update collection version | |
| run: | | |
| # Get version from either release event or workflow run | |
| if [ "${{ github.event_name }}" == "release" ]; then | |
| VERSION="${{ github.event.release.tag_name }}" | |
| else | |
| VERSION="${{ github.event.workflow_run.head_branch }}" | |
| fi | |
| # Read the collection file | |
| COLLECTION=$(cat src/UDNS.postman_collection.json) | |
| # Get the current name and append version | |
| CURRENT_NAME=$(echo "$COLLECTION" | jq -r '.info.name') | |
| NEW_NAME="${CURRENT_NAME} v${VERSION#v}" | |
| # Update the name in the info object | |
| UPDATED_COLLECTION=$(echo "$COLLECTION" | jq --arg name "$NEW_NAME" '.info.name = $name') | |
| # Write back to file | |
| echo "$UPDATED_COLLECTION" > src/UDNS.postman_collection.json | |
| - name: Update environment version | |
| run: | | |
| # Get version from either release event or workflow run | |
| if [ "${{ github.event_name }}" == "release" ]; then | |
| VERSION="${{ github.event.release.tag_name }}" | |
| else | |
| VERSION="${{ github.event.workflow_run.head_branch }}" | |
| fi | |
| # Read the environment file | |
| ENVIRONMENT=$(cat src/UDNS.postman_environment.json) | |
| # Get the current name and append version | |
| CURRENT_NAME=$(echo "$ENVIRONMENT" | jq -r '.name') | |
| NEW_NAME="${CURRENT_NAME} v${VERSION#v}" | |
| # Update the name | |
| UPDATED_ENVIRONMENT=$(echo "$ENVIRONMENT" | jq --arg name "$NEW_NAME" '.name = $name') | |
| # Write back to file | |
| echo "$UPDATED_ENVIRONMENT" > src/UDNS.postman_environment.json | |
| - name: Publish to Postman | |
| env: | |
| POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }} | |
| POSTMAN_WORKSPACE_ID: ${{ secrets.POSTMAN_WORKSPACE_ID }} | |
| POSTMAN_COLLECTION_ID: ${{ secrets.POSTMAN_COLLECTION_ID }} | |
| POSTMAN_ENVIRONMENT_ID: ${{ secrets.POSTMAN_ENVIRONMENT_ID }} | |
| run: | | |
| python scripts/publish_postman.py src/ |