Skip to content

Commit 33cea6a

Browse files
GHA-135 Properly escape quotes in inputs (#61)
Co-authored-by: Peter Trifanov <peter.trifanov@gmail.com>
1 parent 47e57c4 commit 33cea6a

8 files changed

Lines changed: 166 additions & 40 deletions

File tree

.github/workflows/test-create-jira-version.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ jobs:
7878
echo "Action should have determined new-version-name as: 1.2.3"
7979
8080
- name: Test with environment variables
81+
id: test-env
8182
uses: ./create-jira-version
8283
env:
8384
JIRA_PROJECT_KEY: 'TESTPROJ'
@@ -90,3 +91,21 @@ jobs:
9091
echo "Test with environment variables:"
9192
echo "Expected to fail due to missing credentials (which is expected in CI)"
9293
echo "Action should have determined new-version-name as: 2.0.2"
94+
95+
- name: Test with special characters in version names
96+
id: test-special-chars
97+
uses: ./create-jira-version
98+
with:
99+
jira-project-key: 'TESTPROJ'
100+
jira-version-name: '1.2.3-"beta"'
101+
jira-new-version-name: '1.2.4-"rc1"'
102+
use-jira-sandbox: 'true'
103+
continue-on-error: true
104+
105+
- name: Verify special characters test
106+
run: |
107+
echo "Test with special characters in version names:"
108+
echo "Expected to fail due to missing credentials (which is expected in CI)"
109+
echo "Action should handle version names with quotes without syntax errors"
110+
echo "Test outcome: ${{ steps.test-special-chars.outcome }}"
111+
echo "✓ Action handles quotes and special characters in version names"

.github/workflows/test-publish-github-release.yml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,28 +104,55 @@ jobs:
104104
release-version: "test-v1.0.2-${{ github.run_number }}"
105105
release-notes: |
106106
# Test Release Notes
107-
107+
108108
This is a test release with markdown content:
109109
- Feature 1
110110
- Feature 2
111-
111+
112112
## Bug Fixes
113113
- Fix 1
114114
- Fix 2
115115
draft: "true"
116116
continue-on-error: true
117117

118+
- name: Test With Release Notes Containing Quotes
119+
id: test-release-notes-quotes
120+
uses: ./publish-github-release
121+
with:
122+
github-token: ${{ github.token }}
123+
release-version: "test-v1.0.3-${{ github.run_number }}"
124+
release-notes: |
125+
# Release notes - Test - 1.0.3
126+
127+
### New Feature
128+
[SONARIAC-2361](https://example.com) S4830: Server certificates should be verified during SSL/TLS connections
129+
[SONARIAC-2366](https://example.com) S6573: Expanded filenames should not become options
130+
131+
### Improvement
132+
[SONARIAC-2230](https://example.com) S6596 should have different message when tag is present but not compliant
133+
[SONARIAC-2301](https://example.com) Improve "ShellCmdDetector" performance
134+
135+
### Bug
136+
[SONARIAC-2354](https://example.com) Exclude line separators from "shell" text ranges
137+
[TEST-123](https://example.com) Fix issue with "quotes" in title
138+
[TEST-456](https://example.com) Handle 'single quotes' and "double quotes" correctly
139+
[TEST-789](https://example.com) Test with "command -f" in title
140+
draft: "true"
141+
continue-on-error: true
142+
118143
- name: Verify Parameter Tests
119144
run: |
120145
echo "Parameter test results:"
121146
echo "Version input test outcome: ${{ steps.test-version-input.outcome }}"
122147
echo "Custom branch test outcome: ${{ steps.test-custom-branch.outcome }}"
123148
echo "Release notes test outcome: ${{ steps.test-release-notes.outcome }}"
124-
149+
echo "Release notes with quotes test outcome: ${{ steps.test-release-notes-quotes.outcome }}"
150+
125151
# These tests might fail due to workflow triggering issues in test environment
126152
# We're testing that the parameters are accepted without syntax errors
127153
echo "✓ Parameter tests completed without syntax errors"
128154
echo "✓ Action accepts all parameter combinations"
155+
echo "✓ Action handles quotes and special characters in release notes"
129156
130157
environment-variable-tests:
131158
name: Test Environment Variable Usage

.github/workflows/test-update-analyzer.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,35 @@ jobs:
127127
pull-request-body: "Test PR body"
128128
continue-on-error: true
129129

130+
- name: Test With Special Characters in Inputs
131+
id: test-special-chars
132+
uses: ./update-analyzer
133+
with:
134+
release-version: '1.0.0.1'
135+
ticket-key: "SONAR-12345"
136+
plugin-name: 'test-plugin'
137+
plugin-artifacts: 'java,kotlin,"scala"'
138+
secret-name: "test-secret"
139+
pull-request-body: |
140+
Update analyzer to version 1.0.0.1
141+
142+
### Changes
143+
- Fix issue with "quotes" in parser
144+
- Handle 'single quotes' correctly
145+
- Improve "double quoted" strings
146+
continue-on-error: true
147+
130148
- name: Verify Parameter Tests
131149
run: |
132150
echo "Input parameter test results:"
133151
echo "SONAR ticket test outcome: ${{ steps.test-sonar-ticket.outcome }}"
134152
echo "SC ticket test outcome: ${{ steps.test-sc-ticket.outcome }}"
135153
echo "Plugin artifacts test outcome: ${{ steps.test-plugin-artifacts.outcome }}"
136154
echo "Optional parameters test outcome: ${{ steps.test-optional-params.outcome }}"
137-
155+
echo "Special characters test outcome: ${{ steps.test-special-chars.outcome }}"
156+
138157
# All tests are expected to fail due to missing vault access
139158
# We're testing that the parameters are accepted and don't cause syntax errors
140159
echo "✓ All parameter tests completed without syntax errors"
141160
echo "✓ Action accepts all valid input parameter combinations"
161+
echo "✓ Action handles quotes and special characters in inputs"

.github/workflows/test-update-release-ticket-status.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,44 @@ jobs:
3838
run: |
3939
cd update-release-ticket-status
4040
python -m pytest test_update_release_ticket.py -v --cov=update_release_ticket --cov-report=term-missing
41+
42+
integration-tests:
43+
name: Integration Tests
44+
runs-on: ubuntu-latest
45+
46+
steps:
47+
- name: Checkout code
48+
uses: actions/checkout@v4
49+
50+
- name: Test with basic inputs
51+
id: test-basic
52+
uses: ./update-release-ticket-status
53+
with:
54+
release-ticket-key: 'REL-1234'
55+
status: 'In Progress'
56+
use-jira-sandbox: 'true'
57+
continue-on-error: true
58+
59+
- name: Verify basic test
60+
run: |
61+
echo "Test with basic inputs:"
62+
echo "Expected to fail due to missing credentials (which is expected in CI)"
63+
echo "Test outcome: ${{ steps.test-basic.outcome }}"
64+
65+
- name: Test with special characters in inputs
66+
id: test-special-chars
67+
uses: ./update-release-ticket-status
68+
with:
69+
release-ticket-key: 'REL-5678'
70+
status: 'In "Review"'
71+
assignee: 'test.user@example.com'
72+
use-jira-sandbox: 'true'
73+
continue-on-error: true
74+
75+
- name: Verify special characters test
76+
run: |
77+
echo "Test with special characters in inputs:"
78+
echo "Expected to fail due to missing credentials (which is expected in CI)"
79+
echo "Action should handle status values with quotes without syntax errors"
80+
echo "Test outcome: ${{ steps.test-special-chars.outcome }}"
81+
echo "✓ Action handles quotes and special characters in inputs"

create-jira-version/action.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,28 @@ runs:
5252
id: determine-current-version
5353
if: ${{ !inputs.jira-new-version-name }}
5454
shell: bash
55+
env:
56+
INPUT_VERSION: ${{ inputs.jira-version-name || env.JIRA_VERSION_NAME }}
57+
FETCHED_VERSION: ${{ steps.get-jira-version.outputs.jira-version-name }}
5558
run: |
56-
if [[ -n "${{ inputs.jira-version-name || env.JIRA_VERSION_NAME }}" ]]; then
57-
CURRENT_VERSION="${{ inputs.jira-version-name || env.JIRA_VERSION_NAME }}"
59+
if [[ -n "$INPUT_VERSION" ]]; then
60+
CURRENT_VERSION="$INPUT_VERSION"
5861
else
59-
CURRENT_VERSION="${{ steps.get-jira-version.outputs.jira-version-name }}"
62+
CURRENT_VERSION="$FETCHED_VERSION"
6063
fi
6164
echo "current-version-name=$CURRENT_VERSION" >> $GITHUB_OUTPUT
6265
6366
- name: Determine New Jira Version
6467
id: determine-new-version-name
6568
shell: bash
69+
env:
70+
NEW_VERSION_INPUT: ${{ inputs.jira-new-version-name }}
71+
CURRENT_VERSION_OUTPUT: ${{ steps.determine-current-version.outputs.current-version-name }}
6672
run: |
67-
if [[ -n "${{ inputs.jira-new-version-name }}" ]]; then
68-
NEW_VERSION="${{ inputs.jira-new-version-name }}"
73+
if [[ -n "$NEW_VERSION_INPUT" ]]; then
74+
NEW_VERSION="$NEW_VERSION_INPUT"
6975
else
70-
NEW_VERSION=$(echo "${{ steps.determine-current-version.outputs.current-version-name }}" | awk -F. '{$NF+=1; print}' OFS='.')
76+
NEW_VERSION=$(echo "$CURRENT_VERSION_OUTPUT" | awk -F. '{$NF+=1; print}' OFS='.')
7177
fi
7278
echo "new-version-name=$NEW_VERSION" >> $GITHUB_OUTPUT
7379
@@ -79,16 +85,17 @@ runs:
7985
JIRA_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).JIRA_TOKEN }}
8086
JIRA_PROD_URL: "https://sonarsource.atlassian.net/"
8187
JIRA_SANDBOX_URL: "https://sonarsource-sandbox-608.atlassian.net/"
88+
PROJECT_KEY_INPUT: ${{ inputs.jira-project-key || env.JIRA_PROJECT_KEY }}
89+
VERSION_NAME: ${{ steps.determine-new-version-name.outputs.new-version-name }}
90+
JIRA_URL: ${{ ((inputs.use-jira-sandbox || env.USE_JIRA_SANDBOX) == 'true') && env.JIRA_SANDBOX_URL || env.JIRA_PROD_URL }}
8291
run: |
83-
PROJECT_KEY="${{ inputs.jira-project-key || env.JIRA_PROJECT_KEY }}"
84-
85-
if [[ -z "$PROJECT_KEY" ]]; then
92+
if [[ -z "$PROJECT_KEY_INPUT" ]]; then
8693
echo "::error::Both jira-project-key input and JIRA_PROJECT_KEY environment variable are missing. One must be provided."
8794
exit 1
8895
fi
8996
9097
python ${{ github.action_path }}/create_jira_version.py \
91-
--project-key="$PROJECT_KEY" \
92-
--version-name="${{ steps.determine-new-version-name.outputs.new-version-name }}" \
93-
--jira-url="${{ ((inputs.use-jira-sandbox || env.USE_JIRA_SANDBOX) == 'true') && env.JIRA_SANDBOX_URL || env.JIRA_PROD_URL }}" \
98+
--project-key="$PROJECT_KEY_INPUT" \
99+
--version-name="$VERSION_NAME" \
100+
--jira-url="$JIRA_URL" \
94101
>> $GITHUB_OUTPUT

publish-github-release/action.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,25 @@ runs:
4848
echo "VALIDATED_VERSION=$VERSION" >> $GITHUB_ENV
4949
5050
- name: Prepare Release Notes
51+
if: ${{ inputs.release-notes != '' }}
5152
shell: bash
5253
run: |
53-
if [[ -n "${RELEASE_NOTES}" ]]; then
54-
echo "${RELEASE_NOTES}" > release-notes.md
55-
else
56-
echo "" > release-notes.md
57-
fi
54+
echo "${RELEASE_NOTES}" > release-notes.md
5855
env:
5956
RELEASE_NOTES: ${{ inputs.release-notes }}
6057

58+
- name: Prepare Empty Release Notes
59+
if: ${{ inputs.release-notes == '' }}
60+
shell: bash
61+
run: |
62+
echo "" > release-notes.md
63+
6164
- name: Create Release with GitHub CLI
6265
id: create-release
6366
shell: bash
6467
env:
6568
GITHUB_TOKEN: ${{ inputs.github-token }}
69+
HAS_RELEASE_NOTES: ${{ inputs.release-notes != '' }}
6670
run: |
6771
# Check if a release with the same title already exists
6872
EXPECTED_TITLE="$VALIDATED_VERSION"
@@ -104,7 +108,7 @@ runs:
104108
105109
# Build the gh release create command
106110
NOTES_FLAG=""
107-
if [[ -n "${{ inputs.release-notes }}" ]]; then
111+
if [[ "$HAS_RELEASE_NOTES" == "true" ]]; then
108112
NOTES_FLAG="--notes-file release-notes.md"
109113
fi
110114

update-analyzer/action.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,28 @@ runs:
7575

7676
- name: Update analyzer version in build file
7777
shell: bash
78+
env:
79+
PLUGIN_ARTIFACTS: ${{ inputs.plugin-artifacts }}
80+
PLUGIN_NAME: ${{ inputs.plugin-name }}
81+
RELEASE_VERSION: ${{ inputs.release-version }}
7882
run: |
7983
set -euo pipefail
8084
# Prepare the list of plugins to update
81-
if [[ -n "${{ inputs.plugin-artifacts }}" ]]; then
82-
echo "Using plugin-artifacts: ${{ inputs.plugin-artifacts }}"
83-
IFS=',' read -ra PLUGINS <<< "${{ inputs.plugin-artifacts }}"
85+
if [[ -n "$PLUGIN_ARTIFACTS" ]]; then
86+
echo "Using plugin-artifacts: $PLUGIN_ARTIFACTS"
87+
IFS=',' read -ra PLUGINS <<< "$PLUGIN_ARTIFACTS"
8488
else
85-
echo "Using plugin-name: ${{ inputs.plugin-name }}"
86-
PLUGINS=("${{ inputs.plugin-name }}")
89+
echo "Using plugin-name: $PLUGIN_NAME"
90+
PLUGINS=("$PLUGIN_NAME")
8791
fi
88-
92+
8993
# Update each plugin
9094
for plugin in "${PLUGINS[@]}"; do
9195
plugin=$(echo "$plugin" | xargs)
9296
echo "Updating analyzer version in ${{ env.BUILD_GRADLE_FILE }} for plugin $plugin"
93-
sed -i "s/\(:sonar-$plugin.*-plugin:\)[0-9.]*/\1${{ inputs.release-version }}/g" ${{ env.BUILD_GRADLE_FILE }}
97+
sed -i "s/\(:sonar-$plugin.*-plugin:\)[0-9.]*/\1$RELEASE_VERSION/g" ${{ env.BUILD_GRADLE_FILE }}
9498
done
95-
99+
96100
echo "Showing diff:"
97101
git --no-pager diff ${{ env.BUILD_GRADLE_FILE }}
98102

update-release-ticket-status/action.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,23 @@ runs:
4040
- name: Run Python Script to Update Ticket
4141
id: run_python_script
4242
shell: bash
43+
env:
44+
JIRA_USER: ${{ fromJSON(steps.secrets.outputs.vault).JIRA_USER }}
45+
JIRA_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).JIRA_TOKEN }}
46+
JIRA_PROD_URL: "https://sonarsource.atlassian.net/"
47+
JIRA_SANDBOX_URL: "https://sonarsource-sandbox-608.atlassian.net/"
48+
ASSIGNEE_INPUT: ${{ inputs.assignee }}
49+
TICKET_KEY: ${{ inputs.release-ticket-key }}
50+
STATUS: ${{ inputs.status }}
51+
JIRA_URL: ${{ ((inputs.use-jira-sandbox || env.USE_JIRA_SANDBOX) == 'true') && env.JIRA_SANDBOX_URL || env.JIRA_PROD_URL }}
4352
run: |
4453
ASSIGNEE_FLAG=""
45-
if [[ -n "${{ inputs.assignee }}" ]]; then
46-
ASSIGNEE_FLAG="--assignee=${{ inputs.assignee }}"
54+
if [[ -n "$ASSIGNEE_INPUT" ]]; then
55+
ASSIGNEE_FLAG="--assignee=$ASSIGNEE_INPUT"
4756
fi
4857
4958
python ${{ github.action_path }}/update_release_ticket.py \
50-
--ticket-key="${{ inputs.release-ticket-key }}" \
51-
--status="${{ inputs.status }}" \
59+
--ticket-key="$TICKET_KEY" \
60+
--status="$STATUS" \
5261
${ASSIGNEE_FLAG} \
53-
--jira-url="${{ ((inputs.use-jira-sandbox || env.USE_JIRA_SANDBOX) == 'true') && env.JIRA_SANDBOX_URL || env.JIRA_PROD_URL }}"
54-
env:
55-
JIRA_USER: ${{ fromJSON(steps.secrets.outputs.vault).JIRA_USER }}
56-
JIRA_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).JIRA_TOKEN }}
57-
JIRA_PROD_URL: "https://sonarsource.atlassian.net/"
58-
JIRA_SANDBOX_URL: "https://sonarsource-sandbox-608.atlassian.net/"
62+
--jira-url="$JIRA_URL"

0 commit comments

Comments
 (0)