@@ -16,19 +16,22 @@ jobs:
1616 - name : Checkout
1717 uses : actions/checkout@v5
1818 with :
19+ path : genesis
1920 ref : main
2021 fetch-depth : 0
2122
2223 - name : Get last commit SHA
2324 id : current_sha
2425 run : |
26+ cd genesis
2527 CURRENT_SHA=$(git log -n 1 --pretty=format:"%H")
2628 echo "last commit SHA : $CURRENT_SHA"
2729 echo "current_sha=$CURRENT_SHA" >> $GITHUB_OUTPUT
2830
2931 - name : Get last version tag and SHA
3032 id : last_tag
3133 run : |
34+ cd genesis
3235 LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
3336 TAG_SHA=$(git rev-list -n 1 "$LAST_TAG")
3437 echo "Last version SHA : $TAG_SHA"
4750 - name : Get version from changelog
4851 id : changelog_version
4952 run : |
53+ cd genesis
5054 FILE_VERSION=$(grep -m1 '^## ' CHANGELOG.md | sed -E 's/^## ([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
5155 echo "Last version in changelog : $FILE_VERSION"
5256 echo "file_version=$FILE_VERSION" >> $GITHUB_OUTPUT
@@ -70,20 +74,85 @@ jobs:
7074 fi
7175 echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
7276
77+ - name : Clone BPM
78+ uses : actions/checkout@master
79+ with :
80+ repository : InseeFr/BPM
81+ path : bpm
82+
83+ - name : Get BPM version
84+ id : bpm-version
85+ run : |
86+ cd bpm
87+ BPM_VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
88+ echo "bpm_version=$BPM_VERSION" >> $GITHUB_OUTPUT
89+
7390 - name : Update files and commit
7491 run : |
75- #Update poms
92+ cd genesis
93+ BPM_VERSION="${{ steps.bpm-version.outputs.bpm_version }}"
94+ NEW_VERSION="${{ steps.determine_version.outputs.new_version }}"
95+ NEW_VERSION_NO_V="${NEW_VERSION#v}"
96+ FILE="CHANGELOG.md"
97+
98+ #Update BPM version
99+ ##POM
100+ CURRENT_BPM_VERSION=$(grep -oPm1 "(?<=<bpm.version>)[0-9]+\.[0-9]+\.[0-9]+(?=</bpm.version>)" pom.xml)
101+ if [ "$CURRENT_BPM_VERSION" != "$BPM_VERSION" ]; then
102+ echo "BPM version changed!"
103+ sed -i "s|<bpm.version>.*</bpm.version>|<bpm.version>${BPM_VERSION}</bpm.version>|" pom.xml
104+ git add pom.xml
105+
106+ ##Change "Changed" Changelog
107+ NEW_LINE="- BPM ${BPM_VERSION}"
108+ if awk -v ver="^## ${NEW_VERSION_NO_V}" -v line="$NEW_LINE" '
109+ $0 ~ ver {in_ver=1; next}
110+ in_ver && /^## / {exit}
111+ in_ver && $0==line {found=1; exit}
112+ END {exit !found}
113+ ' "$FILE"; then
114+ echo "BPM version already present in changelog"
115+ else
116+ echo "Adding BPM to changelog"
117+ if awk -v ver="^## ${NEW_VERSION_NO_V}" '
118+ $0 ~ ver {in_ver=1; next}
119+ in_ver && /^## / {exit}
120+ in_ver && /^### Updated/ {found=1; exit}
121+ END {exit !found}
122+ ' "$FILE"; then
123+ echo "Adding BPM ${BPM_VERSION} to existing updated section"
124+ awk -v ver="^## ${NEW_VERSION_NO_V}" -v newline="$NEW_LINE" '
125+ $0 ~ ver {print; in_ver=1; next}
126+ in_ver && /^## / {in_ver=0}
127+ in_ver && /^### Updated/ {print; print newline; next}
128+ {print}
129+ ' "$FILE" > tmp && mv tmp "$FILE"
130+ else
131+ ### New changed section
132+ echo "Adding BPM ${BPM_VERSION} to a new updated section"
133+ awk -v ver="^## ${NEW_VERSION_NO_V}" -v newline="$NEW_LINE" '
134+ $0 ~ ver {print; in_ver=1; next}
135+ in_ver && /^## / {print "### Updated"; print newline; in_ver=0}
136+ {print}
137+ END { if(in_ver) {print "### Updated"; print newline} }
138+ ' "$FILE" > tmp && mv tmp "$FILE"
139+ fi
140+ fi
141+ fi
142+
143+ #Update app version
144+ ##Update pom
76145 mvn versions:set -DnewVersion="${{ steps.determine_version.outputs.new_version }}" -DprocessAllModules
77146 mvn versions:commit
78147
79- # Update TODO to today in changelog
148+ ## Update TODO to today in changelog
80149 TODAY=$(date +%Y-%m-%d)
81150 if grep -q '\[TODO\]' CHANGELOG.md; then
82151 sed -i "0,/\[TODO\]/s/\[TODO\]/[$TODAY]/" CHANGELOG.md
83- git add CHANGELOG.md
84152 else
85- echo "No change done in changelog"
153+ echo "No date change done in changelog"
86154 fi
155+ git add CHANGELOG.md
87156
88157 git config user.name 'github-actions'
89158 git config user.email 'github-actions@github.com'
93162 id : create_pr
94163 uses : peter-evans/create-pull-request@v7
95164 with :
165+ path : genesis
96166 token : ${{ secrets.GITHUB_TOKEN }}
97167 base : " main"
98168 commit-message : " Update for release ${{ steps.determine_version.outputs.new_version }}"
@@ -103,7 +173,9 @@ jobs:
103173 labels : " Version Update - Prod"
104174
105175 - name : Merge pull request
106- run : gh pr merge --merge --auto "${{ steps.create_pr.outputs.pull-request-number }}"
176+ run : |
177+ cd genesis
178+ gh pr merge --merge --auto "${{ steps.create_pr.outputs.pull-request-number }}"
107179 env :
108180 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
109181
0 commit comments