Skip to content

Commit

Permalink
feat: Setup CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Feb 1, 2024
1 parent 902ead2 commit c5eac91
Show file tree
Hide file tree
Showing 15 changed files with 7,841 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GITHUB_TOKEN=
CONFIG_FILE_PATH=configuration.toml
GITHUB_TOKEN=

DB_URL=jdbc:h2:./api.db
DB_URL=jdbc:h2:./persistence/revanced-api
DB_USER=
DB_PASSWORD=

Expand Down
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf

# These are Windows script files and should use crlf
*.bat text eol=crlf

26 changes: 26 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Open a PR to main

on:
push:
branches:
- dev
workflow_dispatch:

env:
MESSAGE: Merge branch `${{ github.head_ref || github.ref_name }}` to `main`

jobs:
pull-request:
name: Open pull request
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Open pull request
uses: repo-sync/pull-request@v2
with:
destination_branch: 'main'
pr_title: 'chore: ${{ env.MESSAGE }}'
pr_body: 'This pull request will ${{ env.MESSAGE }}.'
pr_draft: true
89 changes: 89 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Release

on:
workflow_dispatch:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev

jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Make sure the release step uses its own credentials:
# https://github.com/cycjimmy/semantic-release-action#private-packages
persist-credentials: false
fetch-depth: 0

- name: Cache Gradle
uses: burrunan/gradle-cache-action@v1

- name: Build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew build clean

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
cache: 'npm'

- name: Install dependencies
run: npm install

- name: Release
env:
GITHUB_TOKEN: ${{ secrets.REPOSITORY_PUSH_ACCESS }}
run: npm exec semantic-release

- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
image: tonistiigi/binfmt:latest
platforms: all

- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: metadata
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=${{ startsWith(github.ref, 'refs/heads/main') }}
suffix=-${{ github.sha }}
- name: Build and push Docker image
id: build
uses: docker/build-push-action@v5
with:
build-args: GH_TOKEN=${{ secrets.GH_TOKEN }}
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64/v8
cache-to: type=gha,mode=max,ignore-error=true
cache-from: type=gha
push: true
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ out/

### Project ###
.env
configuration.toml
persistence/
configuration.toml
.db
49 changes: 49 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"branches": [
"main",
{
"name": "dev",
"prerelease": true
}
],
"plugins": [
[
"@semantic-release/commit-analyzer", {
"releaseRules": [
{ "type": "build", "scope": "Needs bump", "release": "patch" }
]
}
],
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"gradle-semantic-release-plugin",
[
"@semantic-release/git",
{
"assets": [
"README.md",
"CHANGELOG.md",
"gradle.properties",
]
}
],
[
"@semantic-release/github",
{
"assets": [
{
"path": "build/libs/*.jar"
}
],
successComment: false
}
],
[
"@saithodev/semantic-release-backmerge",
{
backmergeBranches: [{"from": "main", "to": "dev"}],
clearWorkspace: true
}
]
]
}
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM azul/zulu-openjdk:latest

ARG CONFIG_FILE_PATH

ARG DB_URL
ARG DB_USER
ARG DB_PASSWORD

ARG JWT_SECRET
ARG JWT_ISSUER
ARG JWT_VALIDITY_IN_MIN

ARG BASIC_USERNAME
ARG BASIC_PASSWORD

ENV CONFIG_FILE_PATH $CONFIG_FILE_PATH

ENV DB_URL $DB_URL
ENV DB_USER $DB_USER
ENV DB_PASSWORD $DB_PASSWORD

ENV JWT_SECRET $JWT_SECRET
ENV JWT_ISSUER $JWT_ISSUER
ENV JWT_VALIDITY_IN_MIN $JWT_VALIDITY_IN_MIN

ENV BASIC_USERNAME $BASIC_USERNAME
ENV BASIC_PASSWORD $BASIC_PASSWORD

COPY build/libs/revanced-api-*.jar revanced-api.jar

CMD java -jar revanced-api.jar start
Loading

0 comments on commit c5eac91

Please sign in to comment.