Skip to content

Commit ddffee6

Browse files
PVQ-4007 External actions - Move part of build steps into script
- moved 4 steps into bash script for better readability
1 parent 1a65438 commit ddffee6

2 files changed

Lines changed: 63 additions & 50 deletions

File tree

.github/workflows/maven-release.yml

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -100,53 +100,5 @@ jobs:
100100
ref: main
101101
fetch-depth: 0
102102

103-
- name: Check if app is in version history
104-
id: check_version
105-
run: |
106-
if jq -e '.["pdfix-actions"][] | select(.name == "${{ env.ACTION_NAMESPACE }}/${{ env.ACTION_REPOSITORY }}")' pdfix-version-updates/v1/versions.json > /dev/null; then
107-
echo "has_version_history=true" >> $GITHUB_OUTPUT
108-
else
109-
echo "App not found in version history. Skipping update steps."
110-
echo "has_version_history=false" >> $GITHUB_OUTPUT
111-
fi
112-
113-
- name: Update action version and date in versions repository
114-
if: steps.check_version.outputs.has_version_history == 'true'
115-
run: |
116-
cd pdfix-version-updates/v1
117-
TODAY=$(date +%Y-%m-%d)
118-
jq --indent 4 '(.["pdfix-actions"][] | select(.name == "${{ env.ACTION_NAMESPACE }}/${{ env.ACTION_REPOSITORY }}")) |= . + {
119-
"version": "${{ env.tag }}",
120-
"release_date": "'"$TODAY"'"
121-
}' versions.json > tmp.json
122-
mv tmp.json versions.json
123-
cat versions.json
124-
125-
- name: Commit and Push changes into versions repository
126-
if: steps.check_version.outputs.has_version_history == 'true'
127-
run: |
128-
cd pdfix-version-updates
129-
git config user.name "PDFix Support"
130-
git config user.email "support@pdfix.net"
131-
git add v1/versions.json
132-
git commit -m "${{ env.ACTION_NAMESPACE }}/${{ env.ACTION_REPOSITORY }} ${{ env.tag }}"
133-
git push
134-
135-
- name: Tag latest commit with increment in versions repository
136-
if: steps.check_version.outputs.has_version_history == 'true'
137-
run: |
138-
cd pdfix-version-updates
139-
git pull
140-
if git describe --exact-match --tags HEAD > /dev/null 2>&1; then
141-
echo "HEAD already has a tag — skipping tagging."
142-
else
143-
latest_tag=$(git tag -l "v*.*.*" | sort -V | tail -n 1)
144-
echo "Latest tag is: $latest_tag"
145-
version=${latest_tag#v}
146-
IFS='.' read -r major minor patch <<< "$version"
147-
patch=$((patch + 1))
148-
new_tag="v$major.$minor.$patch"
149-
git tag -a "$new_tag" -m "Release $new_tag"
150-
git push origin "$new_tag"
151-
echo "Tagged HEAD with: $new_tag"
152-
fi
103+
- name: Update versions repository with new version
104+
run: chmod +x update_versions_repository.sh && ./update_versions_repository.sh ${{ env.ACTION_NAMESPACE }} ${{ env.ACTION_REPOSITORY }} ${{ env.tag }}

update_versions_repository.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
3+
# This script is used to update versions respository (if )
4+
# This way history is preserved and we can track changes
5+
6+
set -e
7+
8+
# Expecting 3 arguments:
9+
if [ "$#" -ne 3 ]; then
10+
echo "Usage: $0 <DOCKER_HUB_NAMESPACE> <DOCKER_HUB_REPOSITORY> <TAG>"
11+
exit 1
12+
fi
13+
14+
DOCKER_HUB_NAMESPACE=$1
15+
DOCKER_HUB_REPOSITORY=$2
16+
TAG=$3
17+
18+
DOCKER_NAME="${DOCKER_HUB_NAMESPACE}/${DOCKER_HUB_REPOSITORY}"
19+
VERSIONS_JSON="pdfix-version-updates/v1/versions.json"
20+
TEMPORARY_FILE="tmp_versions.json"
21+
22+
# Step 1: Check if app is in version history
23+
if jq -e --arg name "$DOCKER_NAME" '.["pdfix-actions"][] | select(.name == $name)' "$VERSIONS_JSON" > /dev/null; then
24+
echo "App found in version history."
25+
26+
# Step 2: Update action version and date
27+
TODAY=$(date +%Y-%m-%d)
28+
jq --indent 4 --arg name "$DOCKER_NAME" --arg version "$TAG" --arg date "$TODAY" \
29+
'(.["pdfix-actions"][] | select(.name == $name)) |= . + {
30+
"version": $version,
31+
"release_date": $date
32+
}' $VERSIONS_JSON > $TEMPORARY_FILE
33+
mv $TEMPORARY_FILE $VERSIONS_JSON
34+
35+
# Step 3: Commit and push changes
36+
cd pdfix-version-updates
37+
git config user.name "PDFix Support"
38+
git config user.email "support@pdfix.net"
39+
git add v1/versions.json
40+
git commit -m "$DOCKER_NAME $TAG"
41+
git push
42+
43+
# Step 4: Tag latest commit with increment
44+
git pull
45+
if git describe --exact-match --tags HEAD > /dev/null 2>&1; then
46+
echo "HEAD already has a tag — skipping tagging."
47+
else
48+
LATEST_TAG=$(git tag -l "v*.*.*" | sort -V | tail -n 1)
49+
echo "Latest tag is: $LATEST_TAG"
50+
VERSION=${LATEST_TAG#v}
51+
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
52+
PATCH=$((PATCH + 1))
53+
NEW_TAG="v$MAJOR.$MINOR.$PATCH"
54+
git tag -a "$NEW_TAG" -m "Release $NEW_TAG"
55+
git push origin "$NEW_TAG"
56+
echo "Tagged HEAD with: $NEW_TAG"
57+
fi
58+
59+
else
60+
echo "App not found in version history. Skipping update steps."
61+
fi

0 commit comments

Comments
 (0)