Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feat/mfa
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnNiang committed Jan 13, 2024
2 parents 05978f5 + 6830660 commit 074512f
Show file tree
Hide file tree
Showing 101 changed files with 1,411 additions and 948 deletions.
74 changes: 74 additions & 0 deletions .github/actions/docker-buildx-push/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: "Docker buildx and push"
description: "Buildx and push the Docker image."

inputs:
ghcr-token:
description: Token of current GitHub account in GitHub container registry.
required: false
default: ""
dockerhub-user:
description: "User name for the DockerHub account"
required: false
default: ""
dockerhub-token:
description: Token for the DockerHub account
required: false
default: ""
push:
description: Should push the docker image or not.
required: false
default: "false"
platforms:
description: Target platforms for building image
required: false
default: "linux/amd64,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x"
image-name:
description: The basic name of docker.
required: false
default: "halo"

runs:
using: "composite"
steps:
- name: Docker meta for Halo
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/${{ inputs.image-name }}
halohub/${{ inputs.image-name }}
tags: |
type=schedule,pattern=nightly-{{date 'YYYYMMDD'}},enabled=${{ github.event_name == 'schedule' }}
type=ref,event=branch,enabled=${{ github.event_name == 'push' }}
type=ref,event=pr,enabled=${{ github.event_name == 'pull_request' }}
type=semver,pattern={{ version }}
type=semver,pattern={{major}}.{{minor}}
type=sha,enabled=${{ github.event_name == 'push' }}
flavor: |
latest=false
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GHCR
uses: docker/login-action@v3
if: inputs.ghcr-token != '' && github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ inputs.ghcr-token }}
- name: Login to DockerHub
if: inputs.dockerhub-token != '' && github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ inputs.dockerhub-user }}
password: ${{ inputs.dockerhub-token }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: ${{ inputs.platforms }}
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta.outputs.tags }}
push: ${{ (inputs.ghcr-token != '' || inputs.dockerhub-token != '') && inputs.push == 'true' }}
61 changes: 61 additions & 0 deletions .github/actions/setup-env/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Setup Environment
description: Setup environment to check and build Halo, including console and core projects.

inputs:
node-version:
description: Node.js version.
required: false
default: "18"

pnpm-version:
description: pnpm version.
required: false
default: "8"

java-version:
description: Java version.
required: false
default: "17"

runs:
using: "composite"
steps:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.node-version }}

- uses: pnpm/action-setup@v2
name: Setup pnpm
id: pnpm-install
with:
version: ${{ inputs.pnpm-version }}
run_install: false

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH}}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: "temurin"
cache: "gradle"
java-version: ${{ inputs.java-version }}

- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
132 changes: 81 additions & 51 deletions .github/workflows/halo.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Halo CI
name: Halo Workflow

on:
pull_request:
Expand All @@ -16,80 +16,110 @@ on:
- "**"
- "!**.md"
release:
types: # This configuration does not affect the page_build event above
- created
types:
- published

jobs:
check:
test:
if: github.event_name == 'pull_request' || github.event_name == 'push'
runs-on: ubuntu-latest
# Default steps
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
cache: 'gradle'
java-version: 17
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- uses: dorny/paths-filter@v2
id: changes
with:
filters: |
console:
- 'console/**'
- name: Check halo
- name: Setup Environment
uses: ./.github/actions/setup-env
- name: Check Halo console
run: make -C console check
- name: Check Halo core
run: ./gradlew check
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
- name: Analyze code
if: ${{ github.event_name == 'push' }} # Due to inability to access secrets during PR, only the code pushed into the branch can be analyzed.
if: ${{ github.event_name == 'push' && env.SONAR_TOKEN != '' }} # Due to inability to access secrets during PR, only the code pushed into the branch can be analyzed.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew sonar --info
- name: Setup console environment
if: steps.changes.outputs.console == 'true'
uses: halo-sigs/actions/admin-env-setup@main
- name: Check console
if: steps.changes.outputs.console == 'true'
run: make -C console check
build:
runs-on: ubuntu-latest
if: always() && (needs.test.result == 'skipped' || needs.test.result == 'success')
needs: test
steps:
- uses: actions/checkout@v3
- name: Setup Environment
uses: ./.github/actions/setup-env
- name: Build Halo console
run: make -C console build
- name: Reset version of Halo
if: github.event_name == 'release'
shell: bash
run: |
# Set the version with tag name when releasing
version=${{ github.event.release.tag_name }}
version=${version#v}
sed -i "s/version=.*-SNAPSHOT$/version=$version/1" gradle.properties
- name: Build Halo core
run: ./gradlew clean && ./gradlew downloadPluginPresets && ./gradlew build -x check
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: halo-artifacts
path: application/build/libs
retention-days: 1

github-release:
runs-on: ubuntu-latest
if: always() && needs.build.result == 'success' && github.event_name == 'release'
needs: build
steps:
- uses: actions/checkout@v3
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: halo-artifacts
path: application/build/libs
- name: Upload Artifacts
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release upload ${{ github.event.release.tag_name }} application/build/libs/*

docker-build-and-push:
if: always() && needs.build.result == 'success' && (github.event_name == 'push' || github.event_name == 'release')
runs-on: ubuntu-latest
needs: check
needs: build
steps:
- uses: actions/checkout@v3
- uses: halo-sigs/actions/halo-next-docker-build@main # change the version to specific ref or release tag while the action is stable.
if: github.event_name != 'pull_request'
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: halo-artifacts
path: application/build/libs
- name: Docker Buildx and Push
uses: ./.github/actions/docker-buildx-push
with:
image-name: ${{ github.event_name == 'release' && 'halo' || 'halo-dev' }}
ghcr-token: ${{ secrets.GHCR_TOKEN }}
ghcr-token: ${{ secrets.GITHUB_TOKEN }}
dockerhub-user: ${{ secrets.DOCKER_USERNAME }}
dockerhub-token: ${{ secrets.DOCKER_TOKEN }}
push: ${{ github.event_name == 'push' || github.event_name == 'release' }} # we only push to GHCR if the push is to the next branch
console-ref: ${{ github.event_name == 'release' && github.ref || 'main' }}
push: true
platforms: linux/amd64,linux/arm64/v8,linux/ppc64le,linux/s390x
- uses: halo-sigs/actions/halo-next-docker-build@main
if: github.event_name == 'pull_request'

e2e-test:
if: always() && needs.build.result == 'success' && (github.event_name == 'pull_request' || github.event_name == 'push')
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: halo-artifacts
path: application/build/libs
- name: Docker Build
uses: docker/build-push-action@v5
with:
image-name: halo-dev
tags: ghcr.io/halo-dev/halo-dev:main
push: false
console-ref: false
load: true
platforms: ""
context: .
- name: E2E Testing
if: github.event_name == 'pull_request'
run: |
sudo curl -L https://github.com/docker/compose/releases/download/v2.23.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
sudo chmod u+x /usr/local/bin/docker-compose
repo=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')
docker tag ghcr.io/${repo}/halo-dev:pr-${{ github.event.number }} ghcr.io/halo-dev/halo-dev:main
cd e2e && make all
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public enum Operator implements Converter<String, SelectorCriteria> {
public SelectorCriteria convert(@Nullable String selector) {
if (preFlightCheck(selector, 3)) {
var i = selector.indexOf(getOperator());
if (i > 0 && (i + getOperator().length()) < selector.length() - 1) {
if (i > 0 && (i + getOperator().length()) <= selector.length() - 1) {
String key = selector.substring(0, i);
String value = selector.substring(i + getOperator().length());
return new SelectorCriteria(key, this, Set.of(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ record TestCase(String source, Operator converter, SelectorCriteria expected) {
new TestCase("name=", Equals, null),
new TestCase("name=value", Equals,
new SelectorCriteria("name", Equals, Set.of("value"))),
new TestCase("name=v", Equals,
new SelectorCriteria("name", Equals, Set.of("v"))),

new TestCase("", NotEquals, null),
new TestCase("=", NotEquals, null),
Expand Down Expand Up @@ -59,4 +61,4 @@ record TestCase(String source, Operator converter, SelectorCriteria expected) {
assertEquals(testCase.expected(), testCase.converter().convert(testCase.source()));
});
}
}
}
Loading

0 comments on commit 074512f

Please sign in to comment.