Skip to content

Merge pull request #1924 from vasl-developers/temp670b3 #18

Merge pull request #1924 from vasl-developers/temp670b3

Merge pull request #1924 from vasl-developers/temp670b3 #18

name: Build and Release
on:
push:
branches:
- production
workflow_dispatch:
jobs:
build:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
runs-on: ubuntu-latest
steps:
# Step 1: Checkout repository
- name: Checkout repository
uses: actions/checkout@v4
# Step 2: Set up Java environment
- name: Set up Java
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
# Step 3: Cache Maven dependencies
- name: Cache Maven dependencies
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
${{ runner.os }}-
# Step 4: Build the project
- name: Build with Maven
run: mvn clean package
# Step 5: Debug target directory
- name: List target directory contents
run: ls -al ./target
continue-on-error: true
# Step 6: Upload .vmod file artifact
- name: Upload .vmod file artifact
uses: actions/upload-artifact@v4
with:
name: vmod-file
path: target/*.vmod
create-release:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
runs-on: ubuntu-latest
needs: build
outputs:
VERSION: ${{ steps.get_version.outputs.VERSION }}
DOWNLOAD_LINK: ${{ steps.upload_asset.outputs.browser_download_url }}
steps:
# Step 1: Checkout repository
- name: Checkout repository
uses: actions/checkout@v4
# Step 2: Get version dynamically from pom.xml
- name: Get version dynamically from pom.xml
id: get_version
run: |
VERSION=$(grep -oP '(?<=<version>)[^<]+' pom.xml | head -n 1)
echo "VERSION: $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
# Step 3: Check release notes and prepare for GitHub Release
- name: Check for correct version and read release-notes.md
id: process_release_notes
run: |
VERSION=$(grep -oP '(?<=<version>)[^<]+' pom.xml | head -n 1)
NOTES_FILE="dist/release-notes.md"
if [[ ! -f "$NOTES_FILE" ]]; then
echo "Error: $NOTES_FILE not found."
exit 1
fi
if ! head -n 5 "$NOTES_FILE" | grep -q "Version ${VERSION}"; then
echo "Error: Version ${VERSION} not found in the first 5 lines of $NOTES_FILE."
exit 1
fi
# Step 4: Download .vmod file artifact
- name: Download .vmod file artifact
uses: actions/download-artifact@v4
with:
name: vmod-file
path: ./target # Specify the target directory
# Step 5: Verify .vmod file exists
- name: Verify and extract file name
id: extract_file
run: |
VMOD_FILE=$(find ./target -name '*.vmod' -print -quit)
if [[ -z "$VMOD_FILE" ]]; then
echo "Error: No .vmod file found in ./target directory"
exit 1
fi
FILE_NAME=$(basename "$VMOD_FILE")
echo "VMOD_FILE=$VMOD_FILE" >> $GITHUB_ENV
echo "FILE_NAME=$FILE_NAME" >> $GITHUB_ENV
# Step 6: Create GitHub Release
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.VERSION }}
release_name: Release ${{ env.VERSION }}
body_path: dist/release-notes.md
draft: true
prerelease: false
# Step 7: Upload build artifacts (.vmod)
- name: Upload .vmod file to release
id: upload_asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ env.VMOD_FILE }}
asset_name: ${{ env.FILE_NAME }}
asset_content_type: application/octet-stream
update-website:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
runs-on: ubuntu-latest
needs: create-release
steps:
- name: Check if version is beta
id: check_version
run: |
VERSION=${{ needs.create-release.outputs.VERSION }}
if [[ "$VERSION" == *"beta"* ]]; then
echo "This is a beta version. Skipping the rest of the workflow as we will not publish to the website."
echo "IS_BETA=true" >> $GITHUB_ENV
exit 0
else
echo "IS_BETA=false" >> $GITHUB_ENV
fi
- name: Checkout website repository
if: env.IS_BETA != 'true'
uses: actions/checkout@v4
with:
repository: vasl-developers/vasl-website
token: ${{ secrets.GITHUB_TOKEN }}
ref: gh-pages
- name: Checkout main repository
if: env.IS_BETA != 'true'
uses: actions/checkout@v4
with:
repository: vasl-developers/vasl
token: ${{ secrets.GITHUB_TOKEN }}
ref: production
- name: Update download.htm
if: env.IS_BETA != 'true'
run: |
VERSION=${{ needs.create-release.outputs.VERSION }}
DOWNLOAD_LINK=${{ needs.create-release.outputs.DOWNLOAD_LINK }}
UPDATED_DATE=$(date '+%B %d, %Y')
RELEASE_NOTES=$(cat dist/release-notes.md)
# Echo the variables for debugging
echo "VERSION: $VERSION"
echo "DOWNLOAD_LINK: $DOWNLOAD_LINK"
echo "UPDATED_DATE: $UPDATED_DATE"
NEW_DIV="<div class='well table'>
<a id='download${VERSION//./}' class='track btn btn-large btn-primary' href='${DOWNLOAD_LINK}'>VASL ${VERSION}</a>
<h2 class='pull-right'>Updated ${UPDATED_DATE}</h2>
<li>${RELEASE_NOTES}</li>
</div>"
sed -i "/<div class='well table'>/h; \$!b; x; s@</div>@${NEW_DIV}</div>@; x; P; D" download.htm
- name: Wait for manual approval
if: always() && env.IS_BETA != 'true'
uses: peter-evans/repository-dispatch@v2
with:
event-type: manual-approval
- name: Commit and push changes (after approval_
if: ${{ github.event.inputs.approval == 'approved' }} && env.IS_BETA != 'true'
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
git add download.htm
git commit -m "Update download.htm with VASL ${VERSION}"
git push origin gh-pages