Skip to content

Commit

Permalink
This commit includes the CI setup for packaging the jarfile and hosti…
Browse files Browse the repository at this point in the history
…ng them on GitHub's package manager
  • Loading branch information
arkaprovob committed Jul 1, 2023
1 parent 23800f8 commit 69def2f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/build_and_publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Deploy to GitHub Packages

on:
push:
branches:
- main
- feat/ci-cd

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'

- name: Add execute permissions to script
run: chmod +x ./check-version.sh

- name: Check if version exists
id: chkvrsn
run: ./check-version.sh
env:
PAT: ${{ secrets.PAT }}
USER: ${{ secrets.USER }}

- name: Build with Maven
run: mvn -B package --file pom.xml

- name: Publish to GitHub Packages
run: mvn deploy
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
if: ${{ steps.chkvrsn.outputs.exists == 'false' }}
13 changes: 13 additions & 0 deletions check-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
URL=https://maven.pkg.github.com/arkaprovob/gamedoora-model/com/gamedoora/gamedoora-model/$VERSION/gamedoora-model-$VERSION.pom
STATUS_CODE=$(curl --silent --output /dev/null --write-out "%{http_code}\n" -u ${USER}:${PAT} $URL)

if [ $STATUS_CODE -eq 404 ]; then
echo "::set-output name=exists::false"
echo "Version $VERSION does not exist, proceeding with the artifact upload."
else
echo "::set-output name=exists::true"
echo "Version $VERSION already exists."
fi

0 comments on commit 69def2f

Please sign in to comment.