diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..cb16ea1 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,42 @@ +name: publish + +on: + workflow_dispatch: + inputs: + commit-hash: + description: "COMMIT_HASH" + required: false + type: string + default: "default" + +jobs: + build-and-optionally-publish: + runs-on: ubuntu-latest + + permissions: + contents: write + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Build & test (always) + run: | + if [ "${{ github.event.inputs.commit-hash }}" = "default" ]; then + make build-image + else + make build-image COMMIT_HASH=${{ github.event.inputs.commit-hash }} + fi + make all + + - name: Publish (optional) + if: ${{ github.event.inputs.commit-hash != 'default' }} + run: | + echo "Publishing changes..." + git config --global user.email "robot@umbrella"; + git config --global user.name "robot"; + git commit -am "Auto-update with COMMIT_HASH=${{ github.event.inputs.commit-hash }}" || echo "Nothing to commit" + git push + diff --git a/Dockerfile b/Dockerfile index 8b35794..4aac5b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,8 +5,11 @@ RUN apt-get update && apt-get install -y \ sed \ && rm -rf /var/lib/apt/lists/* -ENV ANTLR_VERSION=4.13.2 -ENV COMMIT_HASH=99ceb562485efe2cefe47db042606e38259640c6 +ARG ANTLR_VERSION +ARG COMMIT_HASH + +ENV ANTLR_VERSION=$ANTLR_VERSION +ENV COMMIT_HASH=$COMMIT_HASH ENV ANTLR_VERSION=4.13.2 RUN curl -O https://www.antlr.org/download/antlr-${ANTLR_VERSION}-complete.jar @@ -22,4 +25,4 @@ RUN curl -L -o YQL.g4 https://raw.githubusercontent.com/ydb-platform/ydb/${COMMI RUN sed -i "s/grammar SQLv1Antlr4/grammar YQL/g; s/@GRAMMAR_STRING_CORE_SINGLE@/~('\\\'\' | '\\\\\\\\') | ('\\\\\\\\' .)/g; s/@GRAMMAR_STRING_CORE_DOUBLE@/~('\\\"\' | '\\\\\\\\') | ('\\\\\\\\' .)/g; s/@GRAMMAR_MULTILINE_COMMENT_CORE@/./g" YQL.g4 -CMD ["bash"] \ No newline at end of file +CMD ["bash"] diff --git a/Makefile b/Makefile index 392bd36..4031427 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,9 @@ IMAGE_NAME=yql-antlr-parser:latest -ANTLR_VERSION=4.13.2 CURRENT_DIR := $(shell pwd) +ANTLR_VERSION = 4.13.2 +COMMIT_HASH ?= 99ceb562485efe2cefe47db042606e38259640c6 + .PHONY: build-image clean go python dotnet java all go_clean py_clean build-image all: go python dotnet java @@ -19,13 +21,12 @@ dotnet: build-image docker run --rm -v "$(CURRENT_DIR)/dotnet":/workspace/dotnet $(IMAGE_NAME) \ java -jar /antlr-${ANTLR_VERSION}-complete.jar -Dlanguage=CSharp -package YQLAntlr4Parser -o dotnet YQL.g4 - java: build-image docker run --rm -v "$(CURRENT_DIR)/java":/workspace/java $(IMAGE_NAME) \ java -jar /antlr-${ANTLR_VERSION}-complete.jar -Dlanguage=Java -package yql.antlr4.parser -o java YQL.g4 -build-image: - docker build -t $(IMAGE_NAME) . +build-image: + docker build --build-arg ANTLR_VERSION=$(ANTLR_VERSION) --build-arg COMMIT_HASH=$(COMMIT_HASH) -t $(IMAGE_NAME) . clean: go_clean python_clean dotnet_clean java_clean diff --git a/README.md b/README.md index 4ff2582..d2f5c29 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,10 @@ This project provides different languages code generation of YQL parser using AN ```bash make build-image ``` + _Optional:_ can be generated with prefered COMMIT_HASH from [YDB Repo](https://github.com/ydb-platform/ydb/blob/main/yql/essentials/sql/v1/SQLv1Antlr4.g.in): + ```bash + make build-image COMMIT_HASH=yourcommithashhere + ``` - **`clean`** Cleans all generated files for all languages