From 32201375b49d81475d81f47f0f1816cd0c3a7ea9 Mon Sep 17 00:00:00 2001 From: Dandelion Date: Tue, 8 Aug 2023 15:23:09 +0800 Subject: [PATCH 01/15] Create publish_server_image.yml --- .github/workflows/pushlish_server_image.yml | 122 ++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 .github/workflows/pushlish_server_image.yml diff --git a/.github/workflows/pushlish_server_image.yml b/.github/workflows/pushlish_server_image.yml new file mode 100644 index 0000000..da8942d --- /dev/null +++ b/.github/workflows/pushlish_server_image.yml @@ -0,0 +1,122 @@ +name: Publish hugegraph-server image + +on: + schedule: + - cron: '0 23 * * *' + workflow_dispatch: + inputs: + stable_branch: + required: true + default: 'release-1.0.0' + stable_image_url: + required: true + default: 'hugegraph/hugegraph:1.0.0' + +jobs: + build_latest: + strategy: + matrix: + # wait for the next stable version + # image_type: ['latest', 'stable'] + image_type: ['latest'] + + runs-on: ubuntu-latest + env: + repository_url: apache/hugegraph + latest_branch: master + latest_image_url: hugegraph/hugegraph:latest + stable_branch: release-${{vars.STABLE_VERSION}} + stable_image_url: hugegraph/hugegraph:${{vars.STABLE_VERSION}} + + steps: + - name: Reset If Need + if: github.event_name=='workflow_dispatch' + run: | + echo "stable_branch=${{ inputs.stable_branch }}" >> $GITHUB_ENV + echo "stable_image_url=${{ inputs.stable_image_url }}" >> $GITHUB_ENV + branch_name=${{ matrix.image_type == 'latest' && env.latest_branch || env.stable_branch }} + image_url=${{ matrix.image_type == 'latest' && env.latest_image_url || env.stable_image_url }} + echo "branch_name=$branch_name" >> $GITHUB_ENV + echo "image_url=$image_url" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Checkout latest + uses: actions/checkout@v3 + with: + repository: ${{ env.repository_url }} + ref: ${{ env.branch_name }} + fetch-depth: 2 + + - name: Get current SHA + run: | + current_sha=$(git rev-parse HEAD) + echo "current_sha=$current_sha" >> $GITHUB_ENV + + - name: Get last SHA + run: | + is_update='true' + last_sha=${{ matrix.image_type == 'latest' && vars.LATEST_SHA || vars.STABLE_SHA }} + if [[ "$current_sha" == "$last_sha" ]]; then + is_update='false' + fi + echo "is_update=$is_update" >> $GITHUB_ENV + + - name: Build X86 Image + if: env.is_update == 'true' + uses: docker/build-push-action@v4 + with: + context: . + load: true + tags: ${{ env.image_url }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Test X86 Image + if: env.is_update == 'true' + run: | + docker images + docker run -itd --name=graph -p 18080:8080 $image_url + sleep 20s + curl 0.0.0.0:18080 || exit + docker ps -a + sleep 20s + curl 0.0.0.0:18080 || exit + docker ps -a + + - name: Build ARM & Push all + if: env.is_update == 'true' + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ env.image_url }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Updata last SHA + env: + GITHUB_TOKEN: ${{ secrets.PAT }} + OWNER: hugegraph + REPO: hugegraph-actions + run: | + var_name=${{ matrix.image_type == 'latest' && 'LATEST_SHA' || 'STABLE_SHA' }} + last_sha=${{ matrix.image_type == 'latest' && vars.LATEST_SHA || vars.STABLE_SHA }} + if [[ "$current_sha" != "$last_sha" ]]; then + curl -L \ + -X PATCH \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + -H "Authorization: Bearer ${{ env.GITHUB_TOKEN }}" \ + https://api.github.com/repos/$OWNER/$REPO/actions/variables/$var_name \ + -d '{"name":"'"$var_name"'","value":"'"$current_sha"'"}' + fi \ No newline at end of file From 462743213264756e6b9778029a0f975b3a62ae4f Mon Sep 17 00:00:00 2001 From: Dandelion Date: Tue, 8 Aug 2023 15:34:26 +0800 Subject: [PATCH 02/15] Create publish_server_image.yml --- .github/workflows/pushlish_server_image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pushlish_server_image.yml b/.github/workflows/pushlish_server_image.yml index da8942d..80b9704 100644 --- a/.github/workflows/pushlish_server_image.yml +++ b/.github/workflows/pushlish_server_image.yml @@ -119,4 +119,4 @@ jobs: -H "Authorization: Bearer ${{ env.GITHUB_TOKEN }}" \ https://api.github.com/repos/$OWNER/$REPO/actions/variables/$var_name \ -d '{"name":"'"$var_name"'","value":"'"$current_sha"'"}' - fi \ No newline at end of file + fi From fbb32aa7a7814dd1571c60d919dc7de70d2ae450 Mon Sep 17 00:00:00 2001 From: Dandelion Date: Tue, 22 Aug 2023 19:43:39 +0800 Subject: [PATCH 03/15] Create publish_server_image.yml --- .github/workflows/pushlish_server_image.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/pushlish_server_image.yml b/.github/workflows/pushlish_server_image.yml index 80b9704..0c13b4b 100644 --- a/.github/workflows/pushlish_server_image.yml +++ b/.github/workflows/pushlish_server_image.yml @@ -34,6 +34,9 @@ jobs: run: | echo "stable_branch=${{ inputs.stable_branch }}" >> $GITHUB_ENV echo "stable_image_url=${{ inputs.stable_image_url }}" >> $GITHUB_ENV + + - name: Set branch and image_url + run: | branch_name=${{ matrix.image_type == 'latest' && env.latest_branch || env.stable_branch }} image_url=${{ matrix.image_type == 'latest' && env.latest_image_url || env.stable_image_url }} echo "branch_name=$branch_name" >> $GITHUB_ENV From 95bc76629cb50935641a0f0f333ad524c169f911 Mon Sep 17 00:00:00 2001 From: Dandelion Date: Fri, 25 Aug 2023 14:19:14 +0800 Subject: [PATCH 04/15] feat: support publish_server_image to dockerhub automatically (V2) --- ...ge.yml => publish_latest_server_image.yml} | 52 ++++---------- .../publish_release_server_image.yml | 72 +++++++++++++++++++ 2 files changed, 84 insertions(+), 40 deletions(-) rename .github/workflows/{pushlish_server_image.yml => publish_latest_server_image.yml} (57%) create mode 100644 .github/workflows/publish_release_server_image.yml diff --git a/.github/workflows/pushlish_server_image.yml b/.github/workflows/publish_latest_server_image.yml similarity index 57% rename from .github/workflows/pushlish_server_image.yml rename to .github/workflows/publish_latest_server_image.yml index 0c13b4b..ccaecd3 100644 --- a/.github/workflows/pushlish_server_image.yml +++ b/.github/workflows/publish_latest_server_image.yml @@ -1,47 +1,19 @@ -name: Publish hugegraph-server image - +name: "Publish latest server docker image automatically" +# todo: expand the yaml to deal with multi release version on: schedule: - cron: '0 23 * * *' workflow_dispatch: - inputs: - stable_branch: - required: true - default: 'release-1.0.0' - stable_image_url: - required: true - default: 'hugegraph/hugegraph:1.0.0' jobs: build_latest: - strategy: - matrix: - # wait for the next stable version - # image_type: ['latest', 'stable'] - image_type: ['latest'] - runs-on: ubuntu-latest env: - repository_url: apache/hugegraph - latest_branch: master - latest_image_url: hugegraph/hugegraph:latest - stable_branch: release-${{vars.STABLE_VERSION}} - stable_image_url: hugegraph/hugegraph:${{vars.STABLE_VERSION}} + repository_url: apache/incubator-hugegraph + branch: master + image_url: hugegraph/hugegraph:latest steps: - - name: Reset If Need - if: github.event_name=='workflow_dispatch' - run: | - echo "stable_branch=${{ inputs.stable_branch }}" >> $GITHUB_ENV - echo "stable_image_url=${{ inputs.stable_image_url }}" >> $GITHUB_ENV - - - name: Set branch and image_url - run: | - branch_name=${{ matrix.image_type == 'latest' && env.latest_branch || env.stable_branch }} - image_url=${{ matrix.image_type == 'latest' && env.latest_image_url || env.stable_image_url }} - echo "branch_name=$branch_name" >> $GITHUB_ENV - echo "image_url=$image_url" >> $GITHUB_ENV - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 @@ -55,7 +27,7 @@ jobs: uses: actions/checkout@v3 with: repository: ${{ env.repository_url }} - ref: ${{ env.branch_name }} + ref: ${{ env.branch }} fetch-depth: 2 - name: Get current SHA @@ -66,7 +38,7 @@ jobs: - name: Get last SHA run: | is_update='true' - last_sha=${{ matrix.image_type == 'latest' && vars.LATEST_SHA || vars.STABLE_SHA }} + last_sha=${{vars.LATEST_SHA}} if [[ "$current_sha" == "$last_sha" ]]; then is_update='false' fi @@ -109,11 +81,11 @@ jobs: - name: Updata last SHA env: GITHUB_TOKEN: ${{ secrets.PAT }} - OWNER: hugegraph - REPO: hugegraph-actions + OWNER: aroundabout + REPO: action_demo run: | - var_name=${{ matrix.image_type == 'latest' && 'LATEST_SHA' || 'STABLE_SHA' }} - last_sha=${{ matrix.image_type == 'latest' && vars.LATEST_SHA || vars.STABLE_SHA }} + var_name='LATEST_SHA' + last_sha=${{vars.LATEST_SHA}} if [[ "$current_sha" != "$last_sha" ]]; then curl -L \ -X PATCH \ @@ -121,5 +93,5 @@ jobs: -H "X-GitHub-Api-Version: 2022-11-28" \ -H "Authorization: Bearer ${{ env.GITHUB_TOKEN }}" \ https://api.github.com/repos/$OWNER/$REPO/actions/variables/$var_name \ - -d '{"name":"'"$var_name"'","value":"'"$current_sha"'"}' + -d '{"name":"'"$var_name"'","value":"'"${{ env.current_sha }}"'"}' fi diff --git a/.github/workflows/publish_release_server_image.yml b/.github/workflows/publish_release_server_image.yml new file mode 100644 index 0000000..49539ff --- /dev/null +++ b/.github/workflows/publish_release_server_image.yml @@ -0,0 +1,72 @@ +name: "publish release version server docker image manually" +on: + workflow_dispatch: + inputs: + tag: + required: true + default: '' + branch: + required: false + default: '' + +jobs: + build_latest: + runs-on: ubuntu-latest + env: + repository_url: apache/incubator-hugegraph + image_url: hugegraph/hugegraph:${{inputs.tag}} + branch: release-${{inputs.tag}} + + steps: + - name: Set branch + run: | + branch=${{ inputs.branch=='' && env.branch || inputs.branch }} + echo "branch=$branch" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Checkout latest + uses: actions/checkout@v3 + with: + repository: ${{ env.repository_url }} + ref: ${{ env.branch }} + fetch-depth: 2 + + - name: Build X86 Image + uses: docker/build-push-action@v4 + with: + context: . + load: true + tags: ${{ env.image_url }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Test X86 Image + run: | + echo "$image_url" + docker images + docker run -itd --name=graph -p 18080:8080 ${{env.image_url}} + sleep 20s + curl 0.0.0.0:18080 || exit + docker ps -a + sleep 20s + curl 0.0.0.0:18080 || exit + docker ps -a + + - name: Build ARM & Push all + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ env.image_url }} + cache-from: type=gha + cache-to: type=gha,mode=max From 5d16c12d22def23536fa31b0efade09757ce79d8 Mon Sep 17 00:00:00 2001 From: Dandelion Date: Sat, 26 Aug 2023 10:39:30 +0800 Subject: [PATCH 05/15] feat: support publish_server_image to dockerhub automatically (V2) --- .../workflows/publish_release_server_image.yml | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/.github/workflows/publish_release_server_image.yml b/.github/workflows/publish_release_server_image.yml index 49539ff..386cbd3 100644 --- a/.github/workflows/publish_release_server_image.yml +++ b/.github/workflows/publish_release_server_image.yml @@ -2,11 +2,8 @@ name: "publish release version server docker image manually" on: workflow_dispatch: inputs: - tag: - required: true - default: '' branch: - required: false + required: true default: '' jobs: @@ -14,14 +11,13 @@ jobs: runs-on: ubuntu-latest env: repository_url: apache/incubator-hugegraph - image_url: hugegraph/hugegraph:${{inputs.tag}} - branch: release-${{inputs.tag}} + branch: ${{inputs.branch}} steps: - - name: Set branch + - name: Set image_url run: | - branch=${{ inputs.branch=='' && env.branch || inputs.branch }} - echo "branch=$branch" >> $GITHUB_ENV + image_url=hugegraph/hugegraph:$(echo "${{ inputs.branch }}" | grep -oP '(\d+\.\d+\.\d+)') + echo "image_url=$image_url" >> $GITHUB_ENV - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 @@ -52,7 +48,7 @@ jobs: run: | echo "$image_url" docker images - docker run -itd --name=graph -p 18080:8080 ${{env.image_url}} + docker run -itd --name=graph -p 18080:8080 $image_url sleep 20s curl 0.0.0.0:18080 || exit docker ps -a From 4f0b0edd3ec89729340bb33dc4335b419dc34db6 Mon Sep 17 00:00:00 2001 From: Dandelion Date: Sat, 26 Aug 2023 20:35:51 +0800 Subject: [PATCH 06/15] feat: support publish_server_image to dockerhub automatically (V2) --- .../workflows/publish_latest_server_image.yml | 49 +++++++++---------- .../publish_release_server_image.yml | 7 ++- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/.github/workflows/publish_latest_server_image.yml b/.github/workflows/publish_latest_server_image.yml index ccaecd3..bc96a23 100644 --- a/.github/workflows/publish_latest_server_image.yml +++ b/.github/workflows/publish_latest_server_image.yml @@ -1,4 +1,4 @@ -name: "Publish latest server docker image automatically" +name: "Publish server image(latest)" # todo: expand the yaml to deal with multi release version on: schedule: @@ -9,7 +9,7 @@ jobs: build_latest: runs-on: ubuntu-latest env: - repository_url: apache/incubator-hugegraph + repository_url: apache/hugegraph branch: master image_url: hugegraph/hugegraph:latest @@ -30,19 +30,19 @@ jobs: ref: ${{ env.branch }} fetch-depth: 2 - - name: Get current SHA + - name: Get current commit-hash run: | - current_sha=$(git rev-parse HEAD) - echo "current_sha=$current_sha" >> $GITHUB_ENV + current_commit_hash=$(git rev-parse HEAD) + echo "current_commit_hash=$current_commit_hash" >> $GITHUB_ENV - - name: Get last SHA + - name: Get last commit-hash run: | - is_update='true' - last_sha=${{vars.LATEST_SHA}} - if [[ "$current_sha" == "$last_sha" ]]; then - is_update='false' + last_commit_hash=${{vars.LAST_COMMIT_HASH}} + need_update='false' + if [[ "$current_commit_hash" != "$last_commit_hash" ]]; then + need_update='true' fi - echo "is_update=$is_update" >> $GITHUB_ENV + echo "need_update=$need_update" >> $GITHUB_ENV - name: Build X86 Image if: env.is_update == 'true' @@ -78,20 +78,19 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max - - name: Updata last SHA + - name: Updata last commit-hash + if: env.is_update == 'true' env: GITHUB_TOKEN: ${{ secrets.PAT }} - OWNER: aroundabout - REPO: action_demo + OWNER: hugegraph + REPO: hugegraph-actions run: | - var_name='LATEST_SHA' - last_sha=${{vars.LATEST_SHA}} - if [[ "$current_sha" != "$last_sha" ]]; then - curl -L \ - -X PATCH \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - -H "Authorization: Bearer ${{ env.GITHUB_TOKEN }}" \ - https://api.github.com/repos/$OWNER/$REPO/actions/variables/$var_name \ - -d '{"name":"'"$var_name"'","value":"'"${{ env.current_sha }}"'"}' - fi + var_name='LAST_COMMIT_HASH' + last_commit_hash=${{vars.LAST_COMMIT_HASH}} + curl -L \ + -X PATCH \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + -H "Authorization: Bearer ${{ env.GITHUB_TOKEN }}" \ + https://api.github.com/repos/$OWNER/$REPO/actions/variables/$var_name \ + -d '{"name":"'"$var_name"'","value":"'"$current_commit_hash"'"}' diff --git a/.github/workflows/publish_release_server_image.yml b/.github/workflows/publish_release_server_image.yml index 386cbd3..48478e2 100644 --- a/.github/workflows/publish_release_server_image.yml +++ b/.github/workflows/publish_release_server_image.yml @@ -1,22 +1,25 @@ -name: "publish release version server docker image manually" +name: "Publish server image(release)" on: workflow_dispatch: inputs: branch: required: true default: '' + description: 'The branch name should be like *-x.x.x, for example release-1.0.0' jobs: build_latest: runs-on: ubuntu-latest env: - repository_url: apache/incubator-hugegraph + repository_url: apache/hugegraph branch: ${{inputs.branch}} steps: - name: Set image_url run: | + # The following RegExp matches branch_name like "release-1.0.0" or "release-1.0.0-rc" image_url=hugegraph/hugegraph:$(echo "${{ inputs.branch }}" | grep -oP '(\d+\.\d+\.\d+)') + echo $image_url echo "image_url=$image_url" >> $GITHUB_ENV - name: Set up Docker Buildx From 950d245aa948a03d763e83df9878a825a79d5c28 Mon Sep 17 00:00:00 2001 From: Dandelion Date: Sat, 26 Aug 2023 20:39:07 +0800 Subject: [PATCH 07/15] feat: support publish_server_image to dockerhub automatically (V2) --- .github/workflows/publish_latest_server_image.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish_latest_server_image.yml b/.github/workflows/publish_latest_server_image.yml index bc96a23..2800dd7 100644 --- a/.github/workflows/publish_latest_server_image.yml +++ b/.github/workflows/publish_latest_server_image.yml @@ -45,7 +45,7 @@ jobs: echo "need_update=$need_update" >> $GITHUB_ENV - name: Build X86 Image - if: env.is_update == 'true' + if: env.need_update == 'true' uses: docker/build-push-action@v4 with: context: . @@ -55,7 +55,7 @@ jobs: cache-to: type=gha,mode=max - name: Test X86 Image - if: env.is_update == 'true' + if: env.need_update == 'true' run: | docker images docker run -itd --name=graph -p 18080:8080 $image_url @@ -67,7 +67,7 @@ jobs: docker ps -a - name: Build ARM & Push all - if: env.is_update == 'true' + if: env.need_update == 'true' uses: docker/build-push-action@v4 with: context: . @@ -79,7 +79,7 @@ jobs: cache-to: type=gha,mode=max - name: Updata last commit-hash - if: env.is_update == 'true' + if: env.need_update == 'true' env: GITHUB_TOKEN: ${{ secrets.PAT }} OWNER: hugegraph From ed80fea794b6fd4243e37f2b78e13776b235e27a Mon Sep 17 00:00:00 2001 From: Dandelion Date: Sat, 26 Aug 2023 20:52:14 +0800 Subject: [PATCH 08/15] feat: support publish_server_image to dockerhub automatically (V2) --- .github/workflows/publish_release_server_image.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/publish_release_server_image.yml b/.github/workflows/publish_release_server_image.yml index 48478e2..6dd2172 100644 --- a/.github/workflows/publish_release_server_image.yml +++ b/.github/workflows/publish_release_server_image.yml @@ -17,7 +17,6 @@ jobs: steps: - name: Set image_url run: | - # The following RegExp matches branch_name like "release-1.0.0" or "release-1.0.0-rc" image_url=hugegraph/hugegraph:$(echo "${{ inputs.branch }}" | grep -oP '(\d+\.\d+\.\d+)') echo $image_url echo "image_url=$image_url" >> $GITHUB_ENV From 31bd179234b54dd9f11f7c5a51aa2a8132f313a4 Mon Sep 17 00:00:00 2001 From: Dandelion Date: Sat, 26 Aug 2023 21:44:15 +0800 Subject: [PATCH 09/15] feat: support publish_server_image to dockerhub automatically (V2) --- .github/workflows/publish_latest_server_image.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/publish_latest_server_image.yml b/.github/workflows/publish_latest_server_image.yml index 2800dd7..567b257 100644 --- a/.github/workflows/publish_latest_server_image.yml +++ b/.github/workflows/publish_latest_server_image.yml @@ -44,6 +44,11 @@ jobs: fi echo "need_update=$need_update" >> $GITHUB_ENV + # To do: if github provide support for exit gracefully, replace if statements with exit. + # until 2023, there is no official support from github to use "exit gracefully" + # If exit 0, the left steps still continue. If exit 1, the action will fail. + # https://github.com/actions/runner/issues/662#issuecomment-1506792423 + - name: Build X86 Image if: env.need_update == 'true' uses: docker/build-push-action@v4 From 7162472b576c4266a470bf67ae20635a140db4d3 Mon Sep 17 00:00:00 2001 From: Dandelion <49650772+aroundabout@users.noreply.github.com> Date: Sat, 26 Aug 2023 22:34:42 +0800 Subject: [PATCH 10/15] Update .github/workflows/publish_latest_server_image.yml Co-authored-by: imbajin --- .github/workflows/publish_latest_server_image.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish_latest_server_image.yml b/.github/workflows/publish_latest_server_image.yml index 567b257..fb76fe3 100644 --- a/.github/workflows/publish_latest_server_image.yml +++ b/.github/workflows/publish_latest_server_image.yml @@ -43,11 +43,8 @@ jobs: need_update='true' fi echo "need_update=$need_update" >> $GITHUB_ENV - - # To do: if github provide support for exit gracefully, replace if statements with exit. - # until 2023, there is no official support from github to use "exit gracefully" - # If exit 0, the left steps still continue. If exit 1, the action will fail. - # https://github.com/actions/runner/issues/662#issuecomment-1506792423 + # TODO: replace `if` statements for exit if github provide support for exit gracefully, + # see https://github.com/actions/runner/issues/662 for more details - name: Build X86 Image if: env.need_update == 'true' From ab1eae22a1c26bfcd5e2167fb4e847d511406a12 Mon Sep 17 00:00:00 2001 From: Dandelion <49650772+aroundabout@users.noreply.github.com> Date: Sat, 26 Aug 2023 22:34:53 +0800 Subject: [PATCH 11/15] Update .github/workflows/publish_release_server_image.yml Co-authored-by: imbajin --- .github/workflows/publish_release_server_image.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/publish_release_server_image.yml b/.github/workflows/publish_release_server_image.yml index 6dd2172..ba28361 100644 --- a/.github/workflows/publish_release_server_image.yml +++ b/.github/workflows/publish_release_server_image.yml @@ -18,8 +18,7 @@ jobs: - name: Set image_url run: | image_url=hugegraph/hugegraph:$(echo "${{ inputs.branch }}" | grep -oP '(\d+\.\d+\.\d+)') - echo $image_url - echo "image_url=$image_url" >> $GITHUB_ENV + echo $image_url && echo "image_url=$image_url" >> $GITHUB_ENV - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 From 47e4b79063a87e95f6105f4bbe4dc702a501034b Mon Sep 17 00:00:00 2001 From: Dandelion <49650772+aroundabout@users.noreply.github.com> Date: Sat, 26 Aug 2023 22:35:06 +0800 Subject: [PATCH 12/15] Update .github/workflows/publish_latest_server_image.yml Co-authored-by: imbajin --- .github/workflows/publish_latest_server_image.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/publish_latest_server_image.yml b/.github/workflows/publish_latest_server_image.yml index fb76fe3..a24242c 100644 --- a/.github/workflows/publish_latest_server_image.yml +++ b/.github/workflows/publish_latest_server_image.yml @@ -89,8 +89,7 @@ jobs: run: | var_name='LAST_COMMIT_HASH' last_commit_hash=${{vars.LAST_COMMIT_HASH}} - curl -L \ - -X PATCH \ + curl -L -X PATCH \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ -H "Authorization: Bearer ${{ env.GITHUB_TOKEN }}" \ From 813b45ba15dc1a114a361dc1d7622d56b8152eba Mon Sep 17 00:00:00 2001 From: Dandelion Date: Mon, 28 Aug 2023 23:19:26 +0800 Subject: [PATCH 13/15] feat: support publish_server_image to dockerhub automatically (V2) --- .../workflows/publish_latest_server_image.yml | 53 +++++++++---------- .../publish_release_server_image.yml | 8 +-- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/.github/workflows/publish_latest_server_image.yml b/.github/workflows/publish_latest_server_image.yml index a24242c..2d0469f 100644 --- a/.github/workflows/publish_latest_server_image.yml +++ b/.github/workflows/publish_latest_server_image.yml @@ -1,5 +1,5 @@ name: "Publish server image(latest)" -# todo: expand the yaml to deal with multi release version + on: schedule: - cron: '0 23 * * *' @@ -9,10 +9,14 @@ jobs: build_latest: runs-on: ubuntu-latest env: - repository_url: apache/hugegraph - branch: master - image_url: hugegraph/hugegraph:latest - + REPOSITORY_URL: apache/hugegraph + BRANCH: master + IMAGE_URL: hugegraph/hugegraph:latest + GITHUB_TOKEN: ${{ secrets.PAT }} + OWNER: hugegraph + REPO: actions + LAST_COMMIT_HASH: ${{vars.LAST_COMMIT_HASH}} + steps: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 @@ -26,41 +30,40 @@ jobs: - name: Checkout latest uses: actions/checkout@v3 with: - repository: ${{ env.repository_url }} - ref: ${{ env.branch }} + repository: ${{ env.REPOSITORY_URL }} + ref: ${{ env.BRANCH }} fetch-depth: 2 - name: Get current commit-hash run: | current_commit_hash=$(git rev-parse HEAD) - echo "current_commit_hash=$current_commit_hash" >> $GITHUB_ENV + echo "CURRENT_COMMIT_HASH=$current_commit_hash" >> $GITHUB_ENV - - name: Get last commit-hash + - name: Check if an update is needed run: | - last_commit_hash=${{vars.LAST_COMMIT_HASH}} need_update='false' - if [[ "$current_commit_hash" != "$last_commit_hash" ]]; then + if [[ "$CURRENT_COMMIT_HASH" != "$LAST_COMMIT_HASH" ]]; then need_update='true' fi - echo "need_update=$need_update" >> $GITHUB_ENV + echo "NEED_UPDATE=$need_update" >> $GITHUB_ENV # TODO: replace `if` statements for exit if github provide support for exit gracefully, # see https://github.com/actions/runner/issues/662 for more details - name: Build X86 Image - if: env.need_update == 'true' + if: env.NEED_UPDATE == 'true' uses: docker/build-push-action@v4 with: context: . load: true - tags: ${{ env.image_url }} + tags: ${{ env.IMAGE_URL }} cache-from: type=gha cache-to: type=gha,mode=max - name: Test X86 Image - if: env.need_update == 'true' + if: env.NEED_UPDATE == 'true' run: | docker images - docker run -itd --name=graph -p 18080:8080 $image_url + docker run -itd --name=graph -p 18080:8080 $IMAGE_URL sleep 20s curl 0.0.0.0:18080 || exit docker ps -a @@ -69,29 +72,23 @@ jobs: docker ps -a - name: Build ARM & Push all - if: env.need_update == 'true' + if: env.NEED_UPDATE == 'true' uses: docker/build-push-action@v4 with: context: . file: ./Dockerfile platforms: linux/amd64,linux/arm64 push: true - tags: ${{ env.image_url }} + tags: ${{ env.IMAGE_URL }} cache-from: type=gha cache-to: type=gha,mode=max - name: Updata last commit-hash - if: env.need_update == 'true' - env: - GITHUB_TOKEN: ${{ secrets.PAT }} - OWNER: hugegraph - REPO: hugegraph-actions + if: env.NEED_UPDATE == 'true' run: | - var_name='LAST_COMMIT_HASH' - last_commit_hash=${{vars.LAST_COMMIT_HASH}} curl -L -X PATCH \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ - -H "Authorization: Bearer ${{ env.GITHUB_TOKEN }}" \ - https://api.github.com/repos/$OWNER/$REPO/actions/variables/$var_name \ - -d '{"name":"'"$var_name"'","value":"'"$current_commit_hash"'"}' + -H "Authorization: Bearer $GITHUB_TOKEN" \ + https://api.github.com/repos/$OWNER/$REPO/actions/variables/LAST_COMMIT_HASH \ + -d '{"name":"LAST_COMMIT_HASH","value":"'"$CURRENT_COMMIT_HASH"'"}' \ No newline at end of file diff --git a/.github/workflows/publish_release_server_image.yml b/.github/workflows/publish_release_server_image.yml index ba28361..31d3286 100644 --- a/.github/workflows/publish_release_server_image.yml +++ b/.github/workflows/publish_release_server_image.yml @@ -11,8 +11,8 @@ jobs: build_latest: runs-on: ubuntu-latest env: - repository_url: apache/hugegraph - branch: ${{inputs.branch}} + REPOSITORY_URL: apache/hugegraph + BRANCH: ${{inputs.branch}} steps: - name: Set image_url @@ -32,8 +32,8 @@ jobs: - name: Checkout latest uses: actions/checkout@v3 with: - repository: ${{ env.repository_url }} - ref: ${{ env.branch }} + repository: ${{ env.REPOSITORY_URL }} + ref: ${{ env.BRANCH }} fetch-depth: 2 - name: Build X86 Image From 6fafcfb28c6ae625b2280947f037efc1c95eb256 Mon Sep 17 00:00:00 2001 From: Dandelion Date: Tue, 29 Aug 2023 12:58:44 +0800 Subject: [PATCH 14/15] feat: support publish_server_image to dockerhub automatically (V2) --- .github/workflows/publish_latest_server_image.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish_latest_server_image.yml b/.github/workflows/publish_latest_server_image.yml index 2d0469f..c28e0d2 100644 --- a/.github/workflows/publish_latest_server_image.yml +++ b/.github/workflows/publish_latest_server_image.yml @@ -50,7 +50,7 @@ jobs: # see https://github.com/actions/runner/issues/662 for more details - name: Build X86 Image - if: env.NEED_UPDATE == 'true' + if: ${{ env.NEED_UPDATE == 'true' }} uses: docker/build-push-action@v4 with: context: . @@ -60,7 +60,7 @@ jobs: cache-to: type=gha,mode=max - name: Test X86 Image - if: env.NEED_UPDATE == 'true' + if: ${{ env.NEED_UPDATE == 'true' }} run: | docker images docker run -itd --name=graph -p 18080:8080 $IMAGE_URL @@ -72,7 +72,7 @@ jobs: docker ps -a - name: Build ARM & Push all - if: env.NEED_UPDATE == 'true' + if: ${{ env.NEED_UPDATE == 'true' }} uses: docker/build-push-action@v4 with: context: . @@ -84,11 +84,11 @@ jobs: cache-to: type=gha,mode=max - name: Updata last commit-hash - if: env.NEED_UPDATE == 'true' + if: ${{ env.NEED_UPDATE == 'true' }} run: | curl -L -X PATCH \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ -H "Authorization: Bearer $GITHUB_TOKEN" \ https://api.github.com/repos/$OWNER/$REPO/actions/variables/LAST_COMMIT_HASH \ - -d '{"name":"LAST_COMMIT_HASH","value":"'"$CURRENT_COMMIT_HASH"'"}' \ No newline at end of file + -d '{"name":"LAST_COMMIT_HASH","value":"'"$CURRENT_COMMIT_HASH"'"}' From b5032870fd3a883df6388861da91b77fb9159626 Mon Sep 17 00:00:00 2001 From: Dandelion <49650772+aroundabout@users.noreply.github.com> Date: Fri, 15 Sep 2023 10:11:01 +0800 Subject: [PATCH 15/15] Update .github/workflows/publish_latest_server_image.yml --- .github/workflows/publish_latest_server_image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish_latest_server_image.yml b/.github/workflows/publish_latest_server_image.yml index c28e0d2..54bb55b 100644 --- a/.github/workflows/publish_latest_server_image.yml +++ b/.github/workflows/publish_latest_server_image.yml @@ -12,7 +12,7 @@ jobs: REPOSITORY_URL: apache/hugegraph BRANCH: master IMAGE_URL: hugegraph/hugegraph:latest - GITHUB_TOKEN: ${{ secrets.PAT }} + GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} OWNER: hugegraph REPO: actions LAST_COMMIT_HASH: ${{vars.LAST_COMMIT_HASH}}