resilient/.forgejo/workflows/release.yml
root 71dd64f71b
Some checks failed
Release / release (push) Failing after 3m39s
Update .forgejo/workflows/release.yml
2025-06-26 11:58:19 +01:00

272 lines
No EOL
11 KiB
YAML

name: Release
on:
push:
branches:
- 'release/**'
jobs:
release:
runs-on: docker
steps:
# Install software dependencies into the runner container
- name: Install system dependencies
run: |
apt-get update
apt-get install -y nodejs npm openjdk-17-jdk maven git jq
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which javac))))
echo "JAVA_HOME=$JAVA_HOME" >> $GITHUB_ENV
- name: Check Java and Node versions
run: |
java -version
mvn -v
mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout
node -v
npm -v
# Checkout (clone) a fresh repo source of the project
- name: Checkout repository
uses: actions/checkout@v4
# ##################################################################
# ## THIS IS A RELEASE ##
# ## #1. Get full version string ##
# ## #2. Remove sufix "-SNAPSHOT" from version string ##
# ## And commit ##
# ## #3. Tag the release ##
# ## ##
- name: Extract version from pom.xml
id: version
run: |
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
RELEASE_VERSION="${VERSION/-SNAPSHOT/}"
echo "release_version=$RELEASE_VERSION" >> $GITHUB_OUTPUT
- name: Set release version (remove -SNAPSHOT)
run: |
mvn versions:set -DnewVersion=${{ steps.version.outputs.release_version }}
mvn versions:commit
git config user.name "forgejo-actions"
git config user.email "ci@forgejo.local"
git commit -am "Release ${{ steps.version.outputs.release_version }}"
git push
# Create the release notes (closed issues)
# Must be here, before the new tag, to get closed issued from the LAST TAG to NOW
- name: Generate release notes from closed issues
id: generate_notes
run: |
REPO_OWNER="root"
REPO_NAME="resilient"
TOKEN="${{ secrets.FORGEJO_TOKEN }}"
VERSION="${{ steps.version.outputs.release_version }}"
API_BASE="https://git.oguerreiro.com/api/v1"
# Step 1. Get the latest tag
echo "Step 1 : Fetching latest release tag..."
LATEST_TAG=$(curl -H "Authorization: token $TOKEN" \
"$API_BASE/repos/$REPO_OWNER/$REPO_NAME/tags" \
| jq -r '.[0].name')
if [[ -z "$LATEST_TAG" || "$LATEST_TAG" == "null" ]]; then
# Doesn't have tag. Its the first release
echo "No previous tags found. Assuming first release."
CLOSED_ISSUES=""
else
# Tag found
echo "Latest tag is: $LATEST_TAG"
# Step 2: Get the tag ref object
echo "Step 2 : Fetch tag ref object from tag = $LATEST_TAG"
TAG_REF=$(curl -H "Authorization: token $TOKEN" \
"$API_BASE/repos/$REPO_OWNER/$REPO_NAME/git/refs/tags/$LATEST_TAG")
echo "... TAG_REF is: $TAG_REF"
# Extract the first .object.sha (if it's an array) or directly if it's an object
if echo "$TAG_REF" | jq -e 'type == "array"' >/dev/null; then
echo "... is an array"
TAG_OBJECT_SHA=$(echo "$TAG_REF" | jq -r '.[0].object.sha')
TAG_OBJECT_TYPE=$(echo "$TAG_REF" | jq -r '.[0].object.type')
else
echo "... is an object"
TAG_OBJECT_SHA=$(echo "$TAG_REF" | jq -r '.object.sha')
TAG_OBJECT_TYPE=$(echo "$TAG_REF" | jq -r '.object.type')
fi
echo "... TAG SHA is (1): $TAG_OBJECT_SHA"
echo "... TAG TYPE is (1): $TAG_OBJECT_TYPE"
# Resolve annotated tag to commit SHA
while [ "$TAG_OBJECT_TYPE" != "commit" ]; do
echo "..."
echo "... TAG OBJECT is not of type commit. Try : $API_BASE/repos/$REPO_OWNER/$REPO_NAME/git/$TAG_OBJECT_TYPE/$TAG_OBJECT_SHA"
TAG_OBJECT=$(curl -H "Authorization: token $TOKEN" \
"$API_BASE/repos/$REPO_OWNER/$REPO_NAME/git/tags/$TAG_OBJECT_SHA")
if echo "$TAG_OBJECT" | jq -e 'type == "array"' >/dev/null; then
echo "... ... is an array"
TAG_OBJECT_SHA=$(echo "$v" | jq -r '.[0].object.sha')
TAG_OBJECT_TYPE=$(echo "$TAG_OBJECT" | jq -r '.[0].object.type')
else
echo "... ... is an object"
TAG_OBJECT_SHA=$(echo "$TAG_OBJECT" | jq -r '.object.sha')
TAG_OBJECT_TYPE=$(echo "$TAG_OBJECT" | jq -r '.object.type')
fi
echo "... TAG_OBJECT_SHA is (2): $TAG_OBJECT_SHA"
echo "... TAG_OBJECT_TYPE is (2): $TAG_OBJECT_TYPE"
done
# Step 3: Get the commit date
echo "Step 3 : Get the commit date from commit = $COMMIT_SHA
COMMIT_DATE=$(curl -H "Authorization: token $TOKEN" \
"$API_BASE/repos/$REPO_OWNER/$REPO_NAME/git/commits/$COMMIT_SHA" \
| jq -r '.committer.date')
echo "... Fetching closed issues since $COMMIT_DATE..."
CLOSED_ISSUES_JSON=$(curl -H "Authorization: token $TOKEN" \
"$API_BASE/repos/$REPO_OWNER/$REPO_NAME/issues?state=closed&since=$COMMIT_DATE")
if [[ -z "$CLOSED_ISSUES_JSON" ]]; then
echo "Warning: No closed issues or invalid response."
CLOSED_ISSUES=""
else
CLOSED_ISSUES=$(echo "$CLOSED_ISSUES_JSON" | jq -r '.[] | "- [#\(.number)](\(.html_url)) \(.title)"')
fi
fi
# Build release notes markdown
{
echo "## Release v$VERSION"
echo
if [[ -n "$CLOSED_ISSUES" ]]; then
echo "### Closed Issues"
echo "$CLOSED_ISSUES"
else
echo "No issues closed since last release."
fi
} > release-notes.md
cat release-notes.md
- name: Tag release
run: |
git tag -a v${{ steps.version.outputs.release_version }} -m "Release ${{ steps.version.outputs.release_version }}"
git push origin v${{ steps.version.outputs.release_version }}
# ## ##
# ##################################################################
# Install @Angular dependencies
- name: Install frontend dependencies
if: false # DISABLED for testing. To check if backend build is also doing frontend.
run: |
cd src/main/webapp
npm ci
# Build the frontend
- name: Build frontend
if: false # DISABLED for testing. To check if backend build is also doing frontend.
run: |
cd src/main/webapp
npm run build
# Build the backend (JAR). NOTE: the -Dmaven.download.parallel=false will force MAVEN to have a single connection for downloads, without this I can get "Connection reset"
- name: Build backend (Spring Boot)
if: false # DISABLED for testing. Justo to make it faster to reach the CREATE RELEASE step
run: |
echo "DEBUG Outputs ************************* "
echo "Container hostname: $(hostname)"
echo "Runner working dir: $PWD"
echo "Runner user: $(whoami)"
echo "Listing contents of ~/.m2/repository:"
ls -lhR ~/.m2/repository | head -n 100 || echo "No .m2/repository found"
echo "Disk usage:"
du -sh ~/.m2/repository || echo "No .m2 directory found"
echo " "
echo "BUILD Outputs ************************* "
mvn clean package -Pprod -DskipTests -Dmaven.download.parallel=false -Dmaven.repo.local=/root/.m2/repository -s .forgejo/workflows/ci-settings.xml
container:
image: maven:3.9-eclipse-temurin-17
volumes:
- docker-forgejo_maven-cache:/root/.m2
# Log output
- name: List output files
run: |
ls -lh target/*.jar || true
# save artifacts
- name: Upload backend JAR
uses: actions/upload-artifact@v3
with:
name: app-backend
path: target/resilient*.jar
# Create the release
# NOTE: added system dependency install "jq"
- name: Create release and upload JAR
run: |
VERSION=${{ steps.version.outputs.release_version }}
API="https://git.oguerreiro.com/api/v1"
REPO="root/resilient"
# Create release
RESPONSE=$(curl -s -X POST "$API/repos/$REPO/releases" \
-H "Authorization: token ${{ secrets.FORGEJO_TOKEN }}" \
-H "Content-Type: application/json" \
-d "{
\"tag_name\": \"v$VERSION\",
\"target_commitish\": \"master\",
\"name\": \"Release v$VERSION\",
\"body\": $(jq -Rs < release-notes.md)
}")
RELEASE_ID=$(echo "$RESPONSE" | jq -r '.id')
echo "Created release ID: $RELEASE_ID"
# Upload artifact
curl -s -X POST "$API/repos/$REPO/releases/$RELEASE_ID/assets?name=resilient.jar" \
-H "Authorization: token ${{ secrets.FORGEJO_TOKEN }}" \
-H "Content-Type: application/java-archive" \
--data-binary @"target/resilient*.jar"
# ##################################################################
# ## THIS IS A RELEASE - Change master version to next SNAPSHOT ##
# ## #4. Checkout master ##
# ## #5. Calculate the new version string ##
# ## Update pom.xml ##
# ## Calculate the new version string ##
- name: Checkout main
if: false # DISABLED for testing. DON't atually change master version
uses: actions/checkout@v3
with:
ref: master
- name: Bump to next SNAPSHOT version
if: false # DISABLED for testing. DON't atually change master version
run: |
# Extract the version from the ref, handling tags like v1.0.2 or branches like release/1.0.2
RAW_REF="${GITHUB_REF##*/}" # gets 'v1.0.2' or '1.0.2'
VERSION="${RAW_REF#v}" # strips leading 'v' if present → gives '1.0.2'
echo "Current version: $VERSION"
MAJOR=$(echo "$VERSION" | cut -d. -f1)
MINOR=$(echo "$VERSION" | cut -d. -f2)
PATCH=$(echo "$VERSION" | cut -d. -f3)
NEXT_PATCH=$((PATCH + 1))
NEXT_VERSION="$MAJOR.$MINOR.$NEXT_PATCH-SNAPSHOT"
echo "Next version: $NEXT_VERSION"
mvn versions:set -DnewVersion="$NEXT_VERSION"
mvn versions:commit
git config user.name "forgejo-actions"
git config user.email "ci@forgejo.local"
git commit -am "Start next development cycle $NEXT_VERSION"
git push origin master
# ## ##
# ##################################################################