generated from pagopa/template-java-microservice
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from pagopa/PAGOPA-1211-migrazione-gha-pagopa-…
…spontaneous-payments feat: switching to github actions PAGOPA-1211
- Loading branch information
Showing
47 changed files
with
1,754 additions
and
198 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
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ changelog: | |
exclude: | ||
labels: | ||
- ignore-for-release | ||
- skip | ||
authors: | ||
- pagopa-github-bot | ||
categories: | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,191 @@ | ||
name: Check PR | ||
|
||
# Controls when the workflow will run | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
types: [ opened, synchronize, labeled, unlabeled, reopened, edited ] | ||
|
||
|
||
permissions: | ||
pull-requests: write | ||
|
||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
auto_assign: | ||
name: Auto Assign | ||
|
||
# The type of runner that the job will run on | ||
runs-on: ubuntu-latest | ||
|
||
# Steps represent a sequence of tasks that will be executed as part of the job | ||
steps: | ||
- name: Assign Me | ||
# You may pin to the exact commit or the version. | ||
uses: kentaro-m/[email protected] | ||
with: | ||
configuration-path: '.github/auto_assign.yml' | ||
|
||
check_format: | ||
name: Check Format | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Formatting | ||
id: format | ||
continue-on-error: true | ||
uses: findologic/intellij-format-action@main | ||
with: | ||
path: . | ||
fail-on-changes: false | ||
|
||
- uses: actions/[email protected] | ||
if: steps.format.outcome != 'success' | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
console.log(context); | ||
var comments = await github.rest.issues.listComments({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo | ||
}); | ||
for (const comment of comments.data) { | ||
console.log(comment); | ||
if (comment.body.includes('Comment this PR with')){ | ||
github.rest.issues.deleteComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
comment_id: comment.id | ||
}) | ||
} | ||
} | ||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: 'Comment this PR with *update_code* to update `openapi.json` and format the code. Consider to use pre-commit to format the code.' | ||
}) | ||
core.setFailed('Format your code.') | ||
check_size: | ||
runs-on: ubuntu-latest | ||
name: Check Size | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Check Size | ||
uses: actions/[email protected] | ||
env: | ||
IGNORED_FILES: openapi.json, openapi-node.json | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const additions = context.payload.pull_request.additions || 0 | ||
const deletions = context.payload.pull_request.deletions || 0 | ||
var changes = additions + deletions | ||
console.log('additions: '+additions+' + deletions: '+deletions+ ' = total changes: ' + changes); | ||
const { IGNORED_FILES } = process.env | ||
const ignored_files = IGNORED_FILES.trim().split(',').filter(word => word.length > 0); | ||
if (ignored_files.length > 0){ | ||
var ignored = 0 | ||
const execSync = require('child_process').execSync; | ||
for (const file of IGNORED_FILES.trim().split(',')) { | ||
const ignored_additions_str = execSync('git --no-pager diff --numstat origin/main..origin/${{ github.head_ref}} | grep ' + file + ' | cut -f 1', { encoding: 'utf-8' }) | ||
const ignored_deletions_str = execSync('git --no-pager diff --numstat origin/main..origin/${{ github.head_ref}} | grep ' + file + ' | cut -f 2', { encoding: 'utf-8' }) | ||
const ignored_additions = ignored_additions_str.split('\n').map(elem=> parseInt(elem || 0)).reduce( | ||
(accumulator, currentValue) => accumulator + currentValue, | ||
0); | ||
const ignored_deletions = ignored_deletions_str.split('\n').map(elem=> parseInt(elem || 0)).reduce( | ||
(accumulator, currentValue) => accumulator + currentValue, | ||
0); | ||
ignored += ignored_additions + ignored_deletions; | ||
} | ||
changes -= ignored | ||
console.log('ignored lines: ' + ignored + ' , consider changes: ' + changes); | ||
} | ||
if (changes < 200){ | ||
github.rest.issues.addLabels({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: ['size/small'] | ||
}) | ||
var labels = await github.rest.issues.listLabelsOnIssue({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo | ||
}); | ||
if (labels.data.find(label => label.name == 'size/large')){ | ||
github.rest.issues.removeLabel({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
name: 'size/large' | ||
}) | ||
} | ||
} | ||
if (changes > 400){ | ||
github.rest.issues.addLabels({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: ['size/large'] | ||
}) | ||
var comments = await github.rest.issues.listComments({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo | ||
}); | ||
for (const comment of comments.data) { | ||
if (comment.body.includes('This PR exceeds the recommended size')){ | ||
github.rest.issues.deleteComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
comment_id: comment.id | ||
}) | ||
} | ||
} | ||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: 'This PR exceeds the recommended size of 400 lines. Please make sure you are NOT addressing multiple issues with one PR. _Note this PR might be rejected due to its size._' | ||
}) | ||
var labels = await github.rest.issues.listLabelsOnIssue({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo | ||
}); | ||
if (labels.data.find(label => label.name == 'size/small')){ | ||
github.rest.issues.removeLabel({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
name: 'size/small' | ||
}) | ||
} | ||
} | ||
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,118 @@ | ||
name: Code Review | ||
|
||
# Controls when the workflow will run | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
types: | ||
- opened | ||
- synchronize | ||
- reopened | ||
push: | ||
branches: | ||
- main | ||
|
||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
env: | ||
PROJECT_KEY: "pagopa-spontaneus-payments" | ||
|
||
permissions: | ||
id-token: write | ||
contents: read | ||
deployments: write | ||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
code-review: | ||
name: Code Review | ||
# The type of runner that the job will run on | ||
runs-on: ubuntu-latest | ||
|
||
# Steps represent a sequence of tasks that will be executed as part of the job | ||
steps: | ||
- name: Code Review | ||
uses: pagopa/github-actions-template/[email protected] | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
sonar_token: ${{ secrets.SONAR_TOKEN }} | ||
project_key: ${{env.PROJECT_KEY}} | ||
coverage_exclusions: "**/config/*,**/*Mock*,**/model/**,**/entity/*" | ||
cpd_exclusions: "**/model/**,**/entity/*" | ||
|
||
smoke-test: | ||
name: Smoke Test | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: dev | ||
steps: | ||
- name: Checkout | ||
id: checkout | ||
uses: actions/checkout@1f9a0c22da41e6ebfa534300ef656657ea2c6707 | ||
|
||
- name: Login | ||
id: login | ||
# from https://github.com/Azure/login/commits/master | ||
uses: azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2 | ||
with: | ||
client-id: ${{ secrets.CLIENT_ID }} | ||
tenant-id: ${{ secrets.TENANT_ID }} | ||
subscription-id: ${{ secrets.SUBSCRIPTION_ID }} | ||
|
||
- name: Run Service on Docker | ||
shell: bash | ||
id: run_service_docker | ||
run: | | ||
cd ./docker | ||
chmod +x ./run_docker.sh | ||
./run_docker.sh local | ||
- name: Run Integration Tests | ||
shell: bash | ||
id: run_integration_test | ||
run: | | ||
export SUBKEY=${{ secrets.SUBKEY }} | ||
export CANARY=${{ inputs.canary }} | ||
export CUCUMBER_PUBLISH_TOKEN=${{ secrets.CUCUMBER_PUBLISH_TOKEN }} | ||
cd ./integration-test | ||
chmod +x ./run_integration_test.sh | ||
./run_integration_test.sh local | ||
delete_github_deployments: | ||
runs-on: ubuntu-latest | ||
needs: smoke-test | ||
if: ${{ always() }} | ||
steps: | ||
- name: Delete Previous deployments | ||
uses: actions/github-script@v6 | ||
env: | ||
SHA_HEAD: ${{ (github.event_name == 'pull_request' && github.event.pull_request.head.sha) || github.sha}} | ||
with: | ||
script: | | ||
const { SHA_HEAD } = process.env | ||
const deployments = await github.rest.repos.listDeployments({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
sha: SHA_HEAD | ||
}); | ||
await Promise.all( | ||
deployments.data.map(async (deployment) => { | ||
await github.rest.repos.createDeploymentStatus({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
deployment_id: deployment.id, | ||
state: 'inactive' | ||
}); | ||
return github.rest.repos.deleteDeployment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
deployment_id: deployment.id | ||
}); | ||
}) | ||
); |
Oops, something went wrong.