Skip to content

Stable Build

Stable Build #1694

Workflow file for this run

name: Stable Build
on:
schedule:
- cron: 0 12 * * *
repository_dispatch:
workflow_dispatch:
jobs:
workflowvars:
name: Setup Workflow Vars
runs-on: ubuntu-latest
outputs:
dockermissing: ${{ steps.check_docker_credentials.outputs.missingsecrets }}
rollbarmissing: ${{ steps.check_rollbar_credentials.outputs.missingsecrets }}
branch: ${{ steps.build_env.outputs.branch }}
version: ${{ steps.build_env.outputs.version }}
revision: ${{ steps.build_env.outputs.revision }}
ispublished: ${{ steps.check_published.outputs.ispublished }}
steps:
- name: Get Revision Variables
id: build_env
run: |
LATEST=$(curl --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' --silent "https://api.github.com/repos/PhantomBot/PhantomBot/releases/latest")
echo "::group::Curl Result"
echo ${LATEST}
echo
echo
echo $(echo $LATEST | grep '"tag_name":')
echo "::endgroup::"
BRANCH=$(echo $LATEST | grep '"tag_name":' | sed -E 's/.*"tag_name":\s*"([^"]+)".*/\1/')
SHA=$(curl --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' --silent "https://api.github.com/repos/PhantomBot/PhantomBot/commits/${BRANCH}" | grep '"sha":' | sed -E 's/.*"sha":\s*"([^"]+)".*/\1/')
echo ${BRANCH}
echo "branch=${BRANCH}" >> $GITHUB_OUTPUT
echo ${BRANCH:1}
echo "version=${BRANCH:1}" >> $GITHUB_OUTPUT
echo ${SHA:0:7}
echo "revision=${SHA:0:7}" >> $GITHUB_OUTPUT
- name: Check Docker Credentials
id: check_docker_credentials
env:
DOCKER_USER: ${{ secrets.DOCKER_USER }}
DOCKER_CLITOKEN: ${{ secrets.DOCKER_CLITOKEN }}
DOCKER_REPO_STABLE: ${{ secrets.DOCKER_REPO_STABLE }}
run: |
if [ "${DOCKER_USER}" == "" ]; then
echo "Missing User"
echo "missingsecrets=yes" >> $GITHUB_OUTPUT
elif [ "${DOCKER_CLITOKEN}" == "" ]; then
echo "Missing Cli Token"
echo "missingsecrets=yes" >> $GITHUB_OUTPUT
elif [ "${DOCKER_REPO_STABLE}" == "" ]; then
echo "Missing Repo"
echo "missingsecrets=yes" >> $GITHUB_OUTPUT
else
echo "All secrets present"
echo "missingsecrets=no" >> $GITHUB_OUTPUT
fi
- name: Check Rollbar Credentials
id: check_rollbar_credentials
env:
ROLLBAR_ACCESS_TOKEN: ${{ secrets.ROLLBAR_WRITE_TOKEN }}
run: |
if [ "${ROLLBAR_ACCESS_TOKEN}" == "" ]; then
echo "Missing Rollbar Access Token"
echo "missingsecrets=yes" >> $GITHUB_OUTPUT
else
echo "All secrets present"
echo "missingsecrets=no" >> $GITHUB_OUTPUT
fi
- name: Check Docker Already Published
id: check_published
env:
MISSING: ${{ steps.check_docker_credentials.outputs.missingsecrets }}
DOCKER_REPO_STABLE: ${{ secrets.DOCKER_REPO_STABLE }}
VERSION: ${{ steps.build_env.outputs.version }}
run: |
if [ "${MISSING}" == "no" ]; then
HTTPCODE=$(curl -s -I "https://registry.hub.docker.com/v2/repositories/${DOCKER_REPO_STABLE}/tags/${VERSION}/" | head -n 1 | cut -d$' ' -f2)
echo ${HTTPCODE}
if [ "${HTTPCODE}" == "200" ]; then
echo "Already Published"
echo "ispublished=yes" >> $GITHUB_OUTPUT
else
echo "Not Published"
echo "ispublished=no" >> $GITHUB_OUTPUT
fi
else
echo "No DockerHub"
echo "ispublished=no" >> $GITHUB_OUTPUT
fi
buildtest:
name: Test Build on ubuntu-latest
runs-on: ubuntu-latest
needs: workflowvars
steps:
- name: Checkout PhantomBot Repository
uses: actions/checkout@v4
with:
repository: PhantomBot/PhantomBot
ref: refs/tags/${{ needs.workflowvars.outputs.branch }}
persist-credentials: false
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
- name: Set up Ant
run: sudo apt-get install ant
- name: Build with Ant
run: ant -noinput -buildfile build.xml test
dockertest:
name: Docker test on ubuntu-latest
runs-on: ubuntu-latest
needs: buildtest
timeout-minutes: 5
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
repository: PhantomBot/PhantomBot
persist-credentials: false
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: latest
driver-opts: network=host
- name: Build Docker
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
PROJECT_VERSION=0.0.0
ANT_ARGS=-Dbuildtype=test -Dversion=0.0.0
tags: localhost:5000/tester/phantombot:test
- name: Test with Docker
run: docker run --rm --name phantombot localhost:5000/tester/phantombot:test launch-docker.sh --version
docker:
name: Docker build on ubuntu-latest
runs-on: ubuntu-latest
needs: [buildtest, dockertest, workflowvars]
if: ${{ contains(needs.workflowvars.outputs.dockermissing, 'no') && contains(needs.workflowvars.outputs.ispublished, 'no') }}
steps:
- name: Checkout PhantomBot Repository
uses: actions/checkout@v4
with:
repository: PhantomBot/PhantomBot
ref: refs/tags/${{ needs.workflowvars.outputs.branch }}
persist-credentials: false
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: latest
- name: Login to DockerHub Registry
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_CLITOKEN }}
logout: true
- name: Notify Rollbar of Deploy Start
if: contains(needs.workflowvars.outputs.rollbarmissing, 'no')
id: rollbar_deploy
uses: rollbar/[email protected]
with:
environment: "stable_docker"
version: ${{ needs.workflowvars.outputs.version }}
status: "started"
env:
ROLLBAR_ACCESS_TOKEN: ${{ secrets.ROLLBAR_WRITE_TOKEN }}
ROLLBAR_USERNAME: ${{ github.actor }}
- name: Prep Ant script
env:
BRANCH: ${{ needs.workflowvars.outputs.branch }}
REVISION: ${{ needs.workflowvars.outputs.revision }}
run: |
sed -i -r 's/revision="[A-Za-z0-9._-]+"/revision="'$REVISION'"/;s/branch="[A-Za-z0-9._-]+"/branch="'$BRANCH'"/;s/status="[A-Za-z0-9._-]+"/status="release"/' ivy.xml
echo $?
- name: Build and Push DockerHub
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
PROJECT_VERSION=${{ needs.workflowvars.outputs.version }}
ANT_ARGS=-Dbuildtype=stable -Dfallback.revision=${{ needs.workflowvars.outputs.revision }} -Dversion=${{ needs.workflowvars.outputs.version }} -Drollbar_token=${{ secrets.ROLLBAR_TOKEN }} -Drollbar_endpoint=${{ secrets.ROLLBAR_ENDPOINT }}
tags: |
${{ secrets.DOCKER_REPO_STABLE }}:${{ needs.workflowvars.outputs.version }}
${{ secrets.DOCKER_REPO_STABLE }}:latest
- name: Notify Rollbar of Deploy Failure
if: ${{ contains(needs.workflowvars.outputs.rollbarmissing, 'no') && (failure() || cancelled()) }}
uses: rollbar/[email protected]
with:
environment: "stable_docker"
version: ${{ needs.workflowvars.outputs.version }}
status: "failed"
env:
ROLLBAR_ACCESS_TOKEN: ${{ secrets.ROLLBAR_WRITE_TOKEN }}
ROLLBAR_USERNAME: ${{ github.actor }}
DEPLOY_ID: ${{ steps.rollbar_deploy.outputs.deploy_id }}
- name: Notify Rollbar of Deploy Success
if: ${{ contains(needs.workflowvars.outputs.rollbarmissing, 'no') && success() }}
uses: rollbar/[email protected]
with:
environment: "stable_docker"
version: ${{ needs.workflowvars.outputs.version }}
status: "succeeded"
env:
ROLLBAR_ACCESS_TOKEN: ${{ secrets.ROLLBAR_WRITE_TOKEN }}
ROLLBAR_USERNAME: ${{ github.actor }}
DEPLOY_ID: ${{ steps.rollbar_deploy.outputs.deploy_id }}