-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added workflow for auto-creating sonarcloud projects on merge + added… (
#354)
- Loading branch information
1 parent
4ef5711
commit b5ddaa5
Showing
10 changed files
with
104 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
name: SonarCloud Setup | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- integrations/** | ||
|
||
jobs: | ||
pre-run: | ||
outputs: | ||
changed_integrations: ${{ steps.create-matrix.outputs.INTEGRATIONS_MATRIX }} | ||
count_changed_integrations: ${{steps.changed-integrations.outputs.all_modified_files_count }} | ||
name: Build Sonarcloud scan run | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Get all changed integrations | ||
id: changed-integrations | ||
uses: tj-actions/changed-files@v40 | ||
with: | ||
json: true | ||
dir_names: true | ||
dir_names_max_depth: 2 | ||
files_ignore: | ||
integrations/_infra/** | ||
files: | | ||
integrations/** | ||
- name: Output changes integrations | ||
id: create-matrix | ||
run: | | ||
echo ${{ steps.changed-integrations.outputs.all_changed_files }} | ||
integrations_array=${{ steps.changed-integrations.outputs.all_changed_files }} | ||
echo "INTEGRATIONS_MATRIX=$(jq -cn --argjson integArr $integrations_array '{integrations: $integArr}')" >> $GITHUB_OUTPUT | ||
setup-sonarcloud: | ||
if: ${{ needs.pre-run.outputs.count_changed_integrations > 0 }} | ||
needs: pre-run | ||
runs-on: ubuntu-latest | ||
name: Create new project for integrations | ||
strategy: | ||
matrix: ${{ fromJson(needs.pre-run.outputs.changed_integrations) }} | ||
steps: | ||
- name: Create integration variable | ||
run: | | ||
unsplit_integ="${{ matrix.integrations }}" | ||
integration=${unsplit_integ##*/} | ||
echo "INTEG_NAME=${integration}" >> $GITHUB_ENV | ||
echo "INTEG_PROJECT_ID=port-labs_ocean_${integration}" >> $GITHUB_ENV | ||
integration=$(echo ${integration} | tr '-' '_') # replace '-'' with '_' | ||
integration=$(echo ${integration} | awk '{print toupper($0)}') # Uppercase the string | ||
echo "INTEG_SECRET_NAME=${integration}" >> $GITHUB_ENV | ||
- name: Check if SonarCloud project exists | ||
id: check_project | ||
run: | | ||
PROJECT_EXISTS=$(curl -u ${{ secrets.CREATE_SONARCLOUD_PROJECT_TOKEN }}: -X GET "https://sonarcloud.io/api/projects/search?projects=${{ env.INTEG_PROJECT_ID }}&organization=port-labs" | jq '.components | length > 0') | ||
echo "PROJECT_EXISTS=$PROJECT_EXISTS" >> $GITHUB_ENV | ||
- name: Create SonarCloud project and token | ||
if: env.PROJECT_EXISTS == 'false' | ||
run: | | ||
# Create Project | ||
curl -u ${{ secrets.CREATE_SONARCLOUD_PROJECT_TOKEN }}: -X POST "https://sonarcloud.io/api/projects/create?name=${{ env.INTEG_PROJECT_ID }}&project=Ocean-${{env.INTEG_NAME}}&visibility=public&organization=port-labs" | ||
# Generate Token | ||
SONAR_TOKEN=$(curl -u ${{ secrets.CREATE_SONARCLOUD_PROJECT_TOKEN }}: -X POST "https://sonarcloud.io/api/user_tokens/generate?name=${{env.INTEG_NAME}}-token" | jq -r '.token') | ||
echo "SONAR_TOKEN=$SONAR_TOKEN" >> $GITHUB_ENV | ||
- name: Create GitHub Repo Secret | ||
if: env.SONAR_TOKEN != '' | ||
uses: gliech/create-github-secret-action@v1 | ||
with: | ||
name: ${{ env.INTEG_SECRET_NAME }} | ||
value: ${{ env.SONAR_TOKEN }} | ||
pa_token: ${{ secrets.PA_TOKEN_FOR_SECRET_CREATION }} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
"full_name": "Your name", | ||
"email": "Your address email <[email protected]>", | ||
"release_date": "{% now 'local' %}", | ||
"remove_docker_files": false, | ||
"is_private_integration": true, | ||
"_extensions": [ | ||
"jinja2_time.TimeExtension", | ||
"extensions.VersionExtension" | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
import os | ||
|
||
|
||
def delete_docker_files(): | ||
if "{{ cookiecutter.remove_docker_files }}" == "True": | ||
def handle_private_integration_flags(): | ||
if "{{ cookiecutter.is_private_integration }}" == "True": | ||
os.remove("Dockerfile") | ||
os.remove(".dockerignore") | ||
if "{{ cookiecutter.is_private_integration }}" == "False": | ||
os.remove("sonar-project.properties") | ||
|
||
|
||
if __name__ == "__main__": | ||
delete_docker_files() | ||
handle_private_integration_flags() |
2 changes: 2 additions & 0 deletions
2
port_ocean/cli/cookiecutter/{{cookiecutter.integration_slug}}/sonar-project.properties
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
sonar.projectKey=port-labs_ocean_{{ cookiecutter.integration_name.lower().replace(' ', '-') }} | ||
sonar.organization=port-labs |
This file contains 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