-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: MerchantId added to common header. (#1)
* Workflow to verify PR title added. * Workflow for semantic versioning added. * MerchantId added to CommonHeader and its cross validation added (it must not be null for POS). * Configuration file for semantic versioning added.
- Loading branch information
1 parent
d418981
commit 42007fd
Showing
7 changed files
with
239 additions
and
3 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,48 @@ | ||
name: Pull request validation | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
types: | ||
- opened | ||
- edited | ||
- synchronize | ||
|
||
jobs: | ||
pr-validation: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: PR title validation | ||
uses: amannn/action-semantic-pull-request@v5 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
types: | | ||
docs | ||
refactor | ||
chore | ||
fix | ||
feat | ||
breaking | ||
requireScope: false | ||
subjectPattern: ^[A-Z].+$ | ||
subjectPatternError: | | ||
The subject "{subject}" found in the pull request title "{title}" | ||
doesn't match the configured pattern. Please ensure that the subject | ||
starts with an uppercase character. | ||
wip: false | ||
|
||
- name: Checkout the repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
cache: maven | ||
|
||
- name: Execute unit-testing | ||
run: mvn clean test |
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,83 @@ | ||
name: Release a new version | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- closed | ||
branches: | ||
- main | ||
|
||
jobs: | ||
release: | ||
if: github.event.pull_request.merged == true | ||
|
||
runs-on: ubuntu-latest | ||
|
||
outputs: | ||
new_release_published: ${{ steps.semantic.outputs.new_release_published }} | ||
new_release_version: ${{ steps.semantic.outputs.new_release_version }} | ||
|
||
steps: | ||
# | ||
# Checkout the source code. | ||
# | ||
- name: Checkout the source code | ||
uses: actions/checkout@v3 | ||
with: | ||
token: ${{ secrets.GIT_PAT }} | ||
|
||
# | ||
# Calculation of the new version (dry-run). | ||
# | ||
- name: Calculation of the new version (dry-run) | ||
uses: cycjimmy/semantic-release-action@v3 | ||
id: semantic | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
semantic_version: 19 | ||
branch: main | ||
extra_plugins: | | ||
@semantic-release/[email protected] | ||
@semantic-release/[email protected] | ||
dry_run: true | ||
|
||
# | ||
# Setup the JDK. | ||
# | ||
- name: Setup the JDK | ||
if: steps.semantic.outputs.new_release_published == 'true' | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
cache: maven | ||
|
||
# | ||
# Update of pom.xml with the new version + Git add + commit + push of the updated pom.xml. | ||
# | ||
- name: Update of pom.xml with the new version + Git add + commit + push of the updated pom.xml | ||
if: steps.semantic.outputs.new_release_published == 'true' | ||
run: | | ||
mvn versions:set -DnewVersion=${{ steps.semantic.outputs.new_release_version }} | ||
git config user.name "GitHub Workflow" | ||
git config user.email "<>" | ||
git add pom.xml | ||
git commit -m "pom.xml updated with new version ${{ steps.semantic.outputs.new_release_version }}" | ||
git push origin main | ||
# | ||
# Calculation of the new version (again) with tagging + releasing + etc. | ||
# | ||
- name: Calculation of the new version (again) with tagging + releasing + etc | ||
if: steps.semantic.outputs.new_release_published == 'true' | ||
uses: cycjimmy/semantic-release-action@v3 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
semantic_version: 19 | ||
branch: main | ||
extra_plugins: | | ||
@semantic-release/[email protected] | ||
@semantic-release/[email protected] | ||
dry_run: false |
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,23 @@ | ||
{ | ||
"branches": [ | ||
"main" | ||
], | ||
"ci": false, | ||
"tagFormat": "${version}", | ||
"plugins": [ | ||
[ | ||
"@semantic-release/commit-analyzer", | ||
{ | ||
"preset": "angular", | ||
"releaseRules": [ | ||
{ | ||
"type": "breaking", | ||
"release": "major" | ||
} | ||
] | ||
} | ||
], | ||
"@semantic-release/release-notes-generator", | ||
"@semantic-release/github" | ||
] | ||
} |
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
31 changes: 31 additions & 0 deletions
31
src/main/java/it/gov/pagopa/swclient/mil/validation/constraints/MerchantIdNotNullForPos.java
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,31 @@ | ||
/* | ||
* MerchantIdNotNullForPos.java | ||
* | ||
* 20 gen 2023 | ||
*/ | ||
package it.gov.pagopa.swclient.mil.validation.constraints; | ||
|
||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import javax.validation.Constraint; | ||
import javax.validation.Payload; | ||
|
||
/** | ||
* If Channel equals to POS, the MerchantId must not be null. | ||
* | ||
* @author Antonio Tarricone | ||
*/ | ||
@Documented | ||
@Retention(RUNTIME) | ||
@Target(TYPE) | ||
@Constraint(validatedBy = { MerchantIdNotNullForPosValidator.class }) | ||
public @interface MerchantIdNotNullForPos { | ||
String message() default ""; | ||
Class<?>[] groups() default {}; | ||
Class<? extends Payload>[] payload() default {}; | ||
} |
25 changes: 25 additions & 0 deletions
25
...a/it/gov/pagopa/swclient/mil/validation/constraints/MerchantIdNotNullForPosValidator.java
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,25 @@ | ||
/* | ||
* MerchantIdNotNullForPosValidator.java | ||
* | ||
* 20 gen 2023 | ||
*/ | ||
package it.gov.pagopa.swclient.mil.validation.constraints; | ||
|
||
import javax.validation.ConstraintValidator; | ||
import javax.validation.ConstraintValidatorContext; | ||
|
||
import it.gov.pagopa.swclient.mil.bean.CommonHeader; | ||
|
||
/** | ||
* If Channel equals to POS, the MerchantId must not be null. | ||
* | ||
* @author Antonio Tarricone | ||
*/ | ||
public class MerchantIdNotNullForPosValidator implements ConstraintValidator<MerchantIdNotNullForPos, CommonHeader> { | ||
@Override | ||
public boolean isValid(CommonHeader commonHeader, ConstraintValidatorContext context) { | ||
String channel = commonHeader.getChannel(); | ||
String merchantId = commonHeader.getMerchantId(); | ||
return !(channel != null && channel.equals("POS") && merchantId == null); | ||
} | ||
} |