From 3f1c027df60f48d81d526d08e47b987ec1199377 Mon Sep 17 00:00:00 2001 From: Henry Lee Date: Wed, 15 Nov 2023 11:26:15 +0900 Subject: [PATCH 1/6] chore: check on pr --- .github/workflow/check.yaml | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 .github/workflow/check.yaml diff --git a/.github/workflow/check.yaml b/.github/workflow/check.yaml new file mode 100644 index 0000000..dfda581 --- /dev/null +++ b/.github/workflow/check.yaml @@ -0,0 +1,50 @@ +name: Check configurations + +on: + pull_request: + branches: + - main + +jobs: + find-engines: + runs-on: ubuntu-latest + + permissions: + contents: read + + steps: + - uses: actions/checkout@v4 + - name: Find targets + id: find-targets + run: | + engines=$(ls configures | xargs -I{e} echo \"{e}\" | tr '\n' ',' | sed 's/,$//') + echo "engines=[${engines}]" >> ${GITHUB_OUTPUT} + + outputs: + engines: ${{ steps.find-targets.outputs.engines }} + + find-configurations: + needs: + - find-engines + + strategy: + matrix: + engine: ${{ fromJson(needs.find-engines.outputs.engines) }} + + runs-on: ubuntu-latest + + permissions: + contents: read + + steps: + - uses: actions/checkout@v4 + - name: Fetch main + run: | + git fetch origin main + - name: Find targets + id: find-targets + run: | + + + outputs: + configures: ${{ steps.find-targets.outputs.configures }} From 26ae47b9f8101e90bc3a81530845ca56c36b0e6b Mon Sep 17 00:00:00 2001 From: Henry Lee Date: Wed, 15 Nov 2023 14:30:38 +0900 Subject: [PATCH 2/6] chore: add check on pr --- .github/workflow/check-on-pr.yaml | 73 +++++++++++++++++++++++++++++++ .github/workflow/check.yaml | 50 --------------------- 2 files changed, 73 insertions(+), 50 deletions(-) create mode 100644 .github/workflow/check-on-pr.yaml delete mode 100644 .github/workflow/check.yaml diff --git a/.github/workflow/check-on-pr.yaml b/.github/workflow/check-on-pr.yaml new file mode 100644 index 0000000..a5b083c --- /dev/null +++ b/.github/workflow/check-on-pr.yaml @@ -0,0 +1,73 @@ +name: Check configurations + +on: + pull_request: + branches: + - main + +jobs: + + find-configurations: + runs-on: ubuntu-latest + + permissions: + contents: read + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Find configurations + id: find-targets + run: | + configures=$(git diff --name-only origin/main...HEAD -- configures | grep -e "\.json" | xargs -I{e} echo \"{e}\" | tr '\n' ',' | sed 's/,$//') + echo "configures=[${configures}]" >> ${GITHUB_OUTPUT} + + outputs: + configures: ${{ steps.find-targets.outputs.configures }} + + check-configurations: + needs: + - find-configurations + + strategy: + matrix: + configure: ${{ fromJson(needs.find-configurations.outputs.configures) }} + + runs-on: ubuntu-latest + + permissions: + contents: read + + steps: + - uses: actions/checkout@v4 + - name: Check the configuration file exists + run: test -f ${{ matrix.configure }} && [[ -s ${{ matrix.configure }} ]] + - name: Check the configuration file is valid JSON + run: jq . ${{ matrix.configure }} > /dev/null + + check-all-test-passed: + if: always() + + needs: + - check-configurations + + permissions: + pull-requests: write + + runs-on: ubuntu-latest + + steps: + - run: echo "${{ toJson(needs) }}" + - run: exit 1 + if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} + - uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: ':mega: All tests passed!' + }) \ No newline at end of file diff --git a/.github/workflow/check.yaml b/.github/workflow/check.yaml deleted file mode 100644 index dfda581..0000000 --- a/.github/workflow/check.yaml +++ /dev/null @@ -1,50 +0,0 @@ -name: Check configurations - -on: - pull_request: - branches: - - main - -jobs: - find-engines: - runs-on: ubuntu-latest - - permissions: - contents: read - - steps: - - uses: actions/checkout@v4 - - name: Find targets - id: find-targets - run: | - engines=$(ls configures | xargs -I{e} echo \"{e}\" | tr '\n' ',' | sed 's/,$//') - echo "engines=[${engines}]" >> ${GITHUB_OUTPUT} - - outputs: - engines: ${{ steps.find-targets.outputs.engines }} - - find-configurations: - needs: - - find-engines - - strategy: - matrix: - engine: ${{ fromJson(needs.find-engines.outputs.engines) }} - - runs-on: ubuntu-latest - - permissions: - contents: read - - steps: - - uses: actions/checkout@v4 - - name: Fetch main - run: | - git fetch origin main - - name: Find targets - id: find-targets - run: | - - - outputs: - configures: ${{ steps.find-targets.outputs.configures }} From 3d950ef4b0e55ac15ab4d175cf2551c990feb9e3 Mon Sep 17 00:00:00 2001 From: Henry Lee Date: Wed, 15 Nov 2023 15:56:04 +0900 Subject: [PATCH 3/6] fix: fix location --- .github/{workflow => workflows}/check-on-pr.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{workflow => workflows}/check-on-pr.yaml (100%) diff --git a/.github/workflow/check-on-pr.yaml b/.github/workflows/check-on-pr.yaml similarity index 100% rename from .github/workflow/check-on-pr.yaml rename to .github/workflows/check-on-pr.yaml From 9eefe3ce87850f1965194ea8c753cbeac762cc47 Mon Sep 17 00:00:00 2001 From: Henry Lee Date: Wed, 15 Nov 2023 15:56:52 +0900 Subject: [PATCH 4/6] chore: set up deploy ci --- .github/workflows/build.yaml | 60 +++++++++++++++++++++++++++++++++++ .github/workflows/deploy.yaml | 42 ++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 .github/workflows/build.yaml create mode 100644 .github/workflows/deploy.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..c49f920 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,60 @@ +name: Build an image + +on: + workflow_call: + inputs: + configuration: + required: true + type: string + registry: + required: true + type: string + repo: + required: true + type: string + +env: + REGISTRY: ${{ inputs.registry }} + REPO: ${{ inputs.repo }} + +jobs: + build: + permissions: + contents: read + packages: write + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Extract configurations + id: extract-configurations + run: | + echo "context=$(cat ${{ inputs.configuration }} | jq -r .context)" >> ${GITHUB_OUTPUT} + echo "name=$(cat ${{ inputs.configuration }} | jq -r .name)" >> ${GITHUB_OUTPUT} + echo "tag=$(cat ${{ inputs.configuration }} | jq -r .tag)" >> ${GITHUB_OUTPUT} + export build_args=$(cat ${{ inputs.configuration }} | jq -r .build_args) + { + echo "buildargs<> ${GITHUB_OUTPUT} + - uses: docker/setup-buildx-action@v3 + - uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: docker/build-push-action@v5 + with: + context: ${{ steps.extract-configurations.outputs.context }} + file: ${{ steps.extract-configurations.outputs.context }}/Dockerfile + platforms: linux/amd64 + push: true + tags: | + ${{ env.REGISTRY }}/${{ env.REPO }}/${{ steps.extract-configurations.outputs.name }}:${{ steps.extract-configurations.outputs.tag }} + build-args: ${{ steps.extract-configurations.outputs.buildargs }} + labels: | + org.opencontainers.image.source="https://github.com/${{ env.REPO }}" diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..f61a192 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,42 @@ +name: Build engine images and publish + +on: + push: + branches: + - main + +jobs: + + find-configurations: + runs-on: ubuntu-latest + + permissions: + contents: read + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 2 + - name: Find configurations + id: find-targets + run: | + configures=$(git diff --name-only HEAD^...HEAD -- configures | grep -e "\.json" | xargs -I{e} echo \"{e}\" | tr '\n' ',' | sed 's/,$//') + echo "configures=[${configures}]" >> ${GITHUB_OUTPUT} + + outputs: + configures: ${{ steps.find-targets.outputs.configures }} + + build-and-publish: + needs: + - find-configurations + + if: needs.find-configurations.outputs.configures != '[]' + + strategy: + matrix: + configure: ${{ fromJson(needs.find-configurations.outputs.configures) }} + uses: ./.github/workflows/build.yaml + with: + configuration: ${{ matrix.configure }} + registry: ghcr.io + repo: kupl/kaprese-engines From 83f036931b4f7cd9d31e00fc16404489c3ce1d10 Mon Sep 17 00:00:00 2001 From: Henry Lee Date: Wed, 15 Nov 2023 15:59:33 +0900 Subject: [PATCH 5/6] fix: skip steps when nothing to check --- .github/workflows/check-on-pr.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/check-on-pr.yaml b/.github/workflows/check-on-pr.yaml index a5b083c..0cac376 100644 --- a/.github/workflows/check-on-pr.yaml +++ b/.github/workflows/check-on-pr.yaml @@ -30,6 +30,8 @@ jobs: needs: - find-configurations + if: needs.find-configurations.outputs.configures != '[]' + strategy: matrix: configure: ${{ fromJson(needs.find-configurations.outputs.configures) }} From f4fda1ecf32c24c2d7f1035071fcab227c658210 Mon Sep 17 00:00:00 2001 From: Henry Lee Date: Wed, 15 Nov 2023 16:00:04 +0900 Subject: [PATCH 6/6] perf: remove debugging echo --- .github/workflows/check-on-pr.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/check-on-pr.yaml b/.github/workflows/check-on-pr.yaml index 0cac376..2111d6d 100644 --- a/.github/workflows/check-on-pr.yaml +++ b/.github/workflows/check-on-pr.yaml @@ -60,7 +60,6 @@ jobs: runs-on: ubuntu-latest steps: - - run: echo "${{ toJson(needs) }}" - run: exit 1 if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }} - uses: actions/github-script@v6