Skip to content

Instantly share code, notes, and snippets.

@adiralashiva8
Created April 14, 2026 14:18
Show Gist options
  • Select an option

  • Save adiralashiva8/e79433a240e32e81613680f9f2b4f4a8 to your computer and use it in GitHub Desktop.

Select an option

Save adiralashiva8/e79433a240e32e81613680f9f2b4f4a8 to your computer and use it in GitHub Desktop.
Robotframework: Github actions to perform static code analysis & dry run using github actions
name: Robocop Code Analysis
on:
pull_request:
branches:
- main
jobs:
robocop:
runs-on: linux-x64-small
continue-on-error: true
permissions:
contents: write
security-events: write
checks: write
pull-requests: write
actions: write
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323
with:
files: |
**/*.robot
**/*.resource
- name: Set up Python
if: steps.changed-files.outputs.any_changed == 'true'
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3
with:
python-version: '3.12'
- name: Install dependencies
if: steps.changed-files.outputs.any_changed == 'true'
run: |
python -m pip install --upgrade pip
pip install robotframework-robocop
- name: Run Robocop analysis on changed files
if: steps.changed-files.outputs.any_changed == 'true'
run: |
python -m robocop check --config robot.toml -r all ${{ steps.changed-files.outputs.all_changed_files }} >> robocop.txt
- name: Post Robocop Summary as PR comment
if: always() && steps.changed-files.outputs.any_changed == 'true'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3
with:
script: |
const fs = require('fs');
let commentBody = '## ✅ Robocop: Linting Report\n\n';
// Add text report
if (fs.existsSync('robocop.txt')) {
const txtContent = fs.readFileSync('robocop.txt', 'utf8');
commentBody += '```\n' + txtContent + '\n```\n';
} else {
commentBody += 'No robocop.txt found.\n';
}
// Post the comment
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
name: Robot Dry Run Analysis - Full Repo
on:
pull_request:
branches:
- main
jobs:
robocop:
runs-on: linux-x64-small
continue-on-error: true
permissions:
contents: write
security-events: write
checks: write
pull-requests: write
actions: write
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Robot Dry Run analysis on full repo
run: |
python -m robot --dryrun --console dotted . >> dryrun.txt
- name: Post Robot Dry Run Summary as PR comment
if: always()
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3
with:
script: |
const fs = require('fs');
let commentBody = '## 🔍 Robot: Dry Run Summary - Full Repo\n\n';
// Add text report
if (fs.existsSync('dryrun.txt')) {
const txtContent = fs.readFileSync('dryrun.txt', 'utf8');
commentBody += '```\n' + txtContent + '\n```\n';
} else {
commentBody += 'No dryrun.txt found.\n';
}
// Post the comment
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});
[tool.robocop.format]
skip = [
"AlignTestCasesSection",
"AlignKeywordsSection",
"AlignTemplatedTestCases",
"AlignVariablesSection",
]
select = [
"RenameTestCases",
"RenameKeywords",
"RenameVariables",
"IndentNestedKeywords",
"NormalizeNewLines",
"NormalizeTags",
"NormalizeSeparators",
"NormalizeComments",
"NormalizeAssignments",
"NormalizeSectionHeaderName",
"NormalizeSettingName",
"OrderSettings",
"OrderSettingsSection",
"ReplaceEmptyValues",
"RemoveEmptySettings",
"DiscardEmptySections",
"MergeAndOrderSections",
"ReplaceRunKeywordIf",
"ReplaceReturns",
"ReplaceBreakContinue",
"SplitTooLongLine",
"AlignSettingsSection"
]
line_length = 160
space_count = 4
continuation_indent = 4
separator = "space"
line_ending = "native"
configure = [
"RenameTestCases.enabled=True",
"RenameTestCases.capitalize_each_word=True",
"RenameKeywords.enabled=True",
"RenameKeywords.keyword_case=capitalize_each_word",
"RenameVariables.enabled=True",
"NormalizeTags.enabled=True",
"NormalizeTags.normalize_case=lower",
"SplitTooLongLine.enabled=True",
"SplitTooLongLine.split_on_every_arg=False",
"SplitTooLongLine.line_length=160",
"DiscardEmptySections.enabled=True",
"DiscardEmptySections.allow_only_comments=True",
"MergeAndOrderSections.enabled=True",
"NormalizeNewLines.enabled=True",
"NormalizeNewLines.section_lines=2",
"NormalizeNewLines.test_case_lines=1",
"NormalizeNewLines.keyword_lines=1",
"NormalizeNewLines.consecutive_lines=0",
"ReplaceRunKeywordIf.enabled=True",
"ReplaceReturns.enabled=True",
"ReplaceBreakContinue.enabled=True",
"NormalizeComments.enabled=True",
"NormalizeAssignments.enabled=True",
"NormalizeSectionHeaderName.enabled=True",
"NormalizeSettingName.enabled=True",
"OrderSettings.enabled=True",
"OrderSettingsSection.enabled=True",
"ReplaceEmptyValues.enabled=True",
"RemoveEmptySettings.enabled=True",
"NormalizeSeparators.enabled=False",
"IndentNestedKeywords.enabled=True",
]
[tool.robocop.lint]
ignore = ["DOC01", "DOC02", "DOC03", "DOC04", "LEN02", "MISC09", "DEPR05", "TAG05", "DEPR06", "VAR06", "VAR05"]
configure = [
"non-local-variables-should-be-uppercase.severity=W",
"line-too-long.line_length=160",
"too-many-calls-in-test-case.max_calls=15",
"too-many-calls-in-keyword.max_calls=20",
"too-long-test-case.max_len=30",
"too-few-calls-in-keyword.min_calls=2",
"wrong-case-in-keyword-name.convention=first_word_capitalized",
"empty-library-alias.severity=W",
"duplicated-library.severity=W",
"unused-variable.severity=I"
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment