diff --git a/.github/workflows/publish_latest_loader_image.yml b/.github/workflows/publish_latest_loader_image.yml new file mode 100644 index 0000000..aa187e8 --- /dev/null +++ b/.github/workflows/publish_latest_loader_image.yml @@ -0,0 +1,72 @@ +name: "Publish loader image(latest)" + +on: + schedule: + - cron: '0 23 * * *' + workflow_dispatch: + +jobs: + build_latest: + runs-on: ubuntu-latest + env: + REPOSITORY_URL: apache/hugegraph-toolchain + BRANCH: master + IMAGE_URL: hugegraph/loader:latest + GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + OWNER: hugegraph + REPO: actions + LAST_LOADER_HASH: ${{vars.LAST_LOADER_HASH}} + + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Checkout latest + uses: actions/checkout@v4 + with: + 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 + + - name: Check if an update is needed + run: | + need_update='false' + if [[ "$CURRENT_COMMIT_HASH" != "$LAST_LOADER_HASH" ]]; then + need_update='true' + fi + 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 & ARM And Push All + uses: docker/build-push-action@v5 + if: ${{ env.NEED_UPDATE == 'true' }} + with: + context: . + file: ./hugegraph-loader/Dockerfile + platforms: linux/amd64,linux/arm64 + tags: ${{ env.IMAGE_URL }} + push: true + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Updata last commit-hash + 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_LOADER_HASH \ + -d '{"name":"LAST_LOADER_HASH","value":"'"$CURRENT_COMMIT_HASH"'"}' diff --git a/.github/workflows/publish_latest_server_image.yml b/.github/workflows/publish_latest_server_image.yml index d510bb6..bf2af88 100644 --- a/.github/workflows/publish_latest_server_image.yml +++ b/.github/workflows/publish_latest_server_image.yml @@ -15,7 +15,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} OWNER: hugegraph REPO: actions - LAST_COMMIT_HASH: ${{vars.LAST_COMMIT_HASH}} + LAST_SERVER_HASH: ${{vars.LAST_SERVER_HASH}} steps: - name: Set up Docker Buildx @@ -42,7 +42,7 @@ jobs: - name: Check if an update is needed run: | need_update='false' - if [[ "$CURRENT_COMMIT_HASH" != "$LAST_COMMIT_HASH" ]]; then + if [[ "$CURRENT_COMMIT_HASH" != "$LAST_SERVER_HASH" ]]; then need_update='true' fi echo "NEED_UPDATE=$need_update" >> $GITHUB_ENV @@ -90,5 +90,5 @@ jobs: -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"'"}' + https://api.github.com/repos/$OWNER/$REPO/actions/variables/LAST_SERVER_HASH \ + -d '{"name":"LAST_SERVER_HASH","value":"'"$CURRENT_COMMIT_HASH"'"}' diff --git a/.github/workflows/publish_release_loader_image.yml b/.github/workflows/publish_release_loader_image.yml new file mode 100644 index 0000000..14fd895 --- /dev/null +++ b/.github/workflows/publish_release_loader_image.yml @@ -0,0 +1,48 @@ +name: "Publish loader 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/hugegraph-toolchain + BRANCH: ${{inputs.branch}} + + steps: + - name: Set image_url + run: | + image_url=hugegraph/loader:$(echo "${{ inputs.branch }}" | grep -oP '(\d+\.\d+\.\d+)') + echo $image_url && echo "IMAGE_URL=$image_url" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Checkout latest + uses: actions/checkout@v4 + with: + repository: ${{ env.REPOSITORY_URL }} + ref: ${{ env.BRANCH }} + fetch-depth: 2 + + - name: Build X86 &ARM And Push All + uses: docker/build-push-action@v5 + with: + context: . + file: ./hugegraph-loader/Dockerfile + platforms: linux/amd64,linux/arm64 + tags: ${{ env.IMAGE_URL }} + push: true + cache-from: type=gha + cache-to: type=gha,mode=max