Skip to content

Distinguish between latest and latest-lts #60

Distinguish between latest and latest-lts

Distinguish between latest and latest-lts #60

Workflow file for this run

name: Build service JAR and build/deploy docker image
on: [push]
jobs:
build_jar:
runs-on: ubuntu-latest
outputs:
jar_download_url: ${{ steps.upload_release.outputs.browser_download_url }}
steps:
- uses: actions/checkout@v2
- name: Create java enviroment
uses: actions/setup-java@v1
with:
java-version: '1.8'
- name: Install fonts.jar
run: |
mvn install:install-file -Dfile=demo/fonts/fonts-extension.jar -DgroupId=local.jasperFontOverrides -DartifactId=local.jasperFontOverrides -Dversion=1.0 -Dpackaging=jar -DlocalRepositoryPath=$HOME/.m2/repository
- name: Build jar with maven
run:
mvn package
- name: Version number
id: version_number
run: |
if [ ${{ startsWith(github.ref, 'refs/tags/') }} = true ]; then
VERSION=$(basename ${{ github.ref }})
else
VERSION=ci-latest-$(basename ${{ github.ref }})
PREV_RELEASE=$(curl -s https://api.github.com/repos/$GITHUB_REPOSITORY/releases/tags/$VERSION | jq -r .url)
fi
echo "version=$VERSION" >>$GITHUB_OUTPUT
echo "prev_release=${PREV_RELEASE/null/}" >>$GITHUB_OUTPUT
- name: Reset ci-latest tag
run: |
VERSION=${{ steps.version_number.outputs.version }}
git config --global user.email "ci@github.com"
git config --global user.name "Github CI"
# Workaround for "could not read Username for 'https://github.com': No such device or address"
git remote set-url origin https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY.git
git tag -d $VERSION || true
git push origin :$VERSION || true
git tag -m $VERSION $VERSION
git push --tags
env:
# This token is provided by Actions, you do not need to create your own token.
# The token is only valid for one hour.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: startsWith(steps.version_number.outputs.version, 'ci-latest-')
- name: Create release
id: create_release
uses: actions/create-release@v1.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.version_number.outputs.version }}
release_name: CI Build
draft: false
prerelease: ${{ !startsWith(github.ref, 'refs/tags/') }}
- name: Get generated jar name
id: jasper_name
run: |
cd target/
NAME=$(find jasper-reporting-service-*.jar)
echo "name=$NAME" >>$GITHUB_OUTPUT
- name: Upload release asset
id: upload_release
uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: target/${{ steps.jasper_name.outputs.name }}
asset_name: ${{ steps.jasper_name.outputs.name }}
asset_content_type: application/jar
- name: Delete previous release
run: |
curl -s -H "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-X DELETE ${{ steps.version_number.outputs.prev_release }}
if: steps.version_number.outputs.prev_release != ''
build_docker:
runs-on: ubuntu-latest
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@master
- name: Get version tag
id: get_tag
run: |
if [ ${{ endsWith(github.ref, '-lts') }} = true ]; then
echo "tag=latest-lts,${GITHUB_REF:10}" >>$GITHUB_OUTPUT
else
echo "tag=latest,${GITHUB_REF:10}" >>$GITHUB_OUTPUT
fi
- name: Build and publish docker image
uses: elgohr/Publish-Docker-Github-Action@v5
if: github.event_name != 'pull_request'
env:
JASPER_SERVICE_URL: ${{needs.build_jar.outputs.jar_download_url}}
with:
name: sourcepole/${{ github.event.repository.name }}
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
tags: "${{ steps.get_tag.outputs.tag }}"
buildargs: "JASPER_SERVICE_URL"
needs: build_jar