GHA-213 Add sandbox integration tests for Jira actions #98
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: Test Create Jira Version Action | |
| on: | |
| workflow_call: | |
| pull_request: | |
| paths: | |
| - 'create-jira-version/**' | |
| - '.github/workflows/test-create-jira-version.yml' | |
| push: | |
| branches: | |
| - branch-* | |
| paths: | |
| - 'create-jira-version/**' | |
| - '.github/workflows/test-create-jira-version.yml' | |
| workflow_dispatch: | |
| jobs: | |
| unit-tests: | |
| name: Run Unit Tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| - name: Set up Python | |
| uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 | |
| with: | |
| python-version: '3.10' | |
| - name: Install dependencies | |
| run: | | |
| cd create-jira-version | |
| pip install -r requirements.txt | |
| pip install pytest pytest-cov | |
| - name: Run unit tests | |
| run: | | |
| cd create-jira-version | |
| python -m pytest test_create_jira_version.py -v --cov=create_jira_version --cov-report=term-missing | |
| sandbox-integration-test: | |
| name: Sandbox Integration Test | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
| - name: Set up Python | |
| uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 | |
| with: | |
| python-version: '3.10' | |
| - name: Install sandbox script dependencies | |
| run: pip install jira | |
| - name: Get Jira credentials from Vault | |
| uses: SonarSource/vault-action-wrapper@v3 | |
| id: secrets | |
| with: | |
| secrets: | | |
| development/kv/data/jira user | JIRA_USER; | |
| development/kv/data/jira token | JIRA_TOKEN; | |
| - name: Set up sandbox fixtures | |
| id: setup | |
| working-directory: scripts/jira-sandbox | |
| env: | |
| JIRA_USER: ${{ fromJSON(steps.secrets.outputs.vault).JIRA_USER }} | |
| JIRA_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).JIRA_TOKEN }} | |
| run: | | |
| python setup.py | |
| VERSION_NAME=$(python -c "import json; print(json.load(open('test_state.json'))['version_name'])") | |
| echo "version-name=$VERSION_NAME" >> $GITHUB_OUTPUT | |
| - name: Create next Jira version via action | |
| id: create-version | |
| uses: ./create-jira-version | |
| with: | |
| jira-project-key: 'SONARIAC' | |
| jira-version-name: ${{ steps.setup.outputs.version-name }} | |
| use-jira-sandbox: 'true' | |
| - name: Verify action outputs | |
| run: | | |
| NEW_NAME="${{ steps.create-version.outputs.jira-new-version-name }}" | |
| NEW_ID="${{ steps.create-version.outputs.jira-new-version-id }}" | |
| if [[ -z "$NEW_NAME" || -z "$NEW_ID" ]]; then | |
| echo "❌ Action did not produce expected outputs (name='$NEW_NAME' id='$NEW_ID')" | |
| exit 1 | |
| fi | |
| echo "✅ New version created: $NEW_NAME (id=$NEW_ID)" | |
| - name: Record new version in state for cleanup | |
| if: always() | |
| env: | |
| NEW_VERSION_NAME: ${{ steps.create-version.outputs.jira-new-version-name }} | |
| run: | | |
| python - <<'EOF' | |
| import json, os | |
| state_file = "scripts/jira-sandbox/test_state.json" | |
| new_name = os.environ.get("NEW_VERSION_NAME", "") | |
| if new_name and os.path.exists(state_file): | |
| with open(state_file) as f: | |
| state = json.load(f) | |
| state["next_version_name"] = new_name | |
| with open(state_file, "w") as f: | |
| json.dump(state, f, indent=2) | |
| EOF | |
| - name: Clean up sandbox fixtures | |
| if: always() | |
| working-directory: scripts/jira-sandbox | |
| env: | |
| JIRA_USER: ${{ fromJSON(steps.secrets.outputs.vault).JIRA_USER }} | |
| JIRA_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).JIRA_TOKEN }} | |
| run: python cleanup.py |