You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
a token (secrets PAT) which have the admin right to the target repo
two variables (LATEST_SHA, STABLE_VERSION) to store last SHA of the latest version(master) and stable version(release-1.0.0)
a variables(STABLE_VERSION) of the stable version
Because the github api do not provide the “create and update” api of the repository variable, admin should create variables first.
Because we cannot directly use the apache repo to build and push image, we can only get the branch by github api instead of the webhook or github event.
If we want to push different version images, we should use the loop (shell or js) in github action, because I do not find the github action syntax(Workflow syntax for GitHub Actions - GitHub Docs). But it might be a little complex and hard to maintain. Do you have any advise?
Or, for example, the stable version is update to v1.1.0, the v1.0.0 will not update. In this case we can change the variables to 1.1.0.
Main process
checkout the apache/hugegraph branch master
get the latest sha
compare with the sha in repo variables
if changed, update the var in the repo and publish docker image (with latest tag)
then create another job to publish the stable version (with the version tag).
demo yaml:
name: "Docker Server Image"on:
schedule:
- cron: '0 23 * * 1'workflow_dispatch:
inputs:
repository_url:
required: truedefault: 'apache/hugegraph'latest_branch:
required: truedefault: 'master'latest_image_url:
required: truedefault: 'hugegraph/hugegraph:latest'stable_branch:
required: truedefault: 'release-1.0.0'stable_image_url:
required: truedefault: 'hugegraph/hugegraph:1.0.0'jobs:
build_latest:
runs-on: ubuntu-latestenv:
repository_url: apache/hugegraphlatest_branch: masterlatest_image_url: hugegraph/hugegraph:lateststable_branch: release-${{vars.STABLE_VERSION}}stable_image_url: hugegraph/hugegraph:${{vars.STABLE_VERSION}}steps:
-
name: Reset If Needif: github.event_name=='workflow_dispatch'run: | echo "repository_url=${{ inputs.repository_url }}" >> $GITHUB_ENV echo "latest_branch=${{ inputs.latest_branch }}" >> $GITHUB_ENV echo "latest_image_url=${{ inputs.latest_image_url }}" >> $GITHUB_ENV echo "stable_branch=${{ inputs.stable_branch }}" >> $GITHUB_ENV echo "stable_image_url=${{ inputs.stable_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:# #registry: ${{ inputs.image_url }}# username: ${{ secrets.DOCKERHUB_USERNAME }}# password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Checkout latestuses: actions/checkout@v3with:
repository: ${{ env.repository_url }}ref: ${{ env.latest_branch }}fetch-depth: 2
- name: Get current SHArun: | latest_current_sha=$(git rev-parse HEAD) echo "latest_current_sha=$latest_current_sha" >> $GITHUB_ENV
- name: Get last SHAenv:
GITHUB_TOKEN: ${{ secrets.PAT }}OWNER: aroundaboutREPO: action_demorun: | echo $latest_current_sha if [[ "$latest_current_sha" == "${{ vars.LATEST_SHA }}" ]]; then echo "sha is the same, do not update docker image" exit 0 else 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/LATEST_SHA \ -d '{"name":"LATEST_SHA","value":"'"$latest_current_sha"'"}' fi# the step to build and push docker image like https://github.com/imbajin/nocode/blob/master/.github/workflows/server-docker.yml# following the the next job to build and publish the stable version
Other methods
repository dispatch event — It still needs the token to set the token to other repo, and the token to target repo cannot be leaked. Hence, secrets is needed, which cannot be provided by apache.
artifacts — It can only upload and download the file in one workflow. If the workflow finished, you cannot use github api to download it
Feature Description (功能描述)
subtask of [Featuer] Support build docker image from Dockerfile (Task Summary) #840
Key idea
Requirement
Maybe the repo in the org is better.
If we want to push different version images, we should use the loop (shell or js) in github action, because I do not find the github action syntax(Workflow syntax for GitHub Actions - GitHub Docs). But it might be a little complex and hard to maintain. Do you have any advise?
Or, for example, the stable version is update to v1.1.0, the v1.0.0 will not update. In this case we can change the variables to 1.1.0.
Main process
demo yaml:
Other methods
BTW #840 [Featuer]->[Feature]
The text was updated successfully, but these errors were encountered: