nextjs-ollama-ui:latest #244
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: issue-sync | |
on: | |
issues: | |
types: | |
- opened | |
- reopened | |
env: | |
HUAWEICLOUD_IAM_AK: "${{ secrets.HUAWEICLOUD_IAM_AK }}" | |
HUAWEICLOUD_IAM_SK: "${{ secrets.HUAWEICLOUD_IAM_SK }}" | |
GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | |
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token | |
permissions: | |
issues: write | |
jobs: | |
build: | |
name: issue-sync | |
runs-on: ubuntu-latest | |
steps: | |
- name: git checkout | |
uses: actions/checkout@v4 | |
- name: welcome | |
run: | | |
set -ex | |
gh issue comment ${{ github.event.issue.number }} -b "Hi @${{ github.event.issue.user.login }}, 正在处理您的issue...<br><br>[详情请查看](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" | |
- name: add label sync-image | |
if: contains(github.event.issue.body, 'sync-image') | |
run: | | |
set -ex | |
gh issue edit ${{ github.event.issue.number }} --add-label "sync-image" | |
echo -n " sync-image" >> label.txt | |
- name: add label x86_64 | |
if: contains(github.event.issue.body, 'x86_64') | |
run: | | |
set -ex | |
gh issue edit ${{ github.event.issue.number }} --add-label "x86_64" | |
echo -n " x86_64" >> label.txt | |
- name: add label aarch64 | |
if: contains(github.event.issue.body, 'aarch64') | |
run: | | |
set -ex | |
gh issue edit ${{ github.event.issue.number }} --add-label "aarch64" | |
echo -n " aarch64" >> label.txt | |
- name: check sync condition | |
run: | | |
set -ex | |
sleep 3s | |
issue_author="${{ github.event.issue.user.login }}" | |
if [[ ${issue_author} != "ganecheng" && ${issue_author} != "C772746954" && ${issue_author} != "if-believe" ]]; then | |
gh issue comment ${{ github.event.issue.number }} -b "issue检查不通过, 需要满足以下3个条件的issue才会开启镜像自动同步<br><br>由 @ganecheng, @C772746954, @if-believe 提交<br>添加了sync-image标签<br>添加了镜像架构标签x86_64或aarch64" | |
exit 1 | |
fi | |
label_list="$(cat label.txt)" | |
if [[ ${label_list} != *sync-image* ]]; then | |
gh issue comment ${{ github.event.issue.number }} -b "issue检查不通过, 需要满足以下3个条件的issue才会开启镜像自动同步<br><br>由 @ganecheng, @C772746954, @if-believe 提交<br>添加了sync-image标签<br>添加了镜像架构标签x86_64或aarch64" | |
exit 1 | |
fi | |
if [[ ${label_list} != *x86_64* && ${label_list} != *aarch64* ]]; then | |
gh issue comment ${{ github.event.issue.number }} -b "issue检查不通过, 需要满足以下3个条件的issue才会开启镜像自动同步<br><br>由 @ganecheng, @C772746954, @if-believe 提交<br>添加了sync-image标签<br>添加了镜像架构标签x86_64或aarch64" | |
exit 1 | |
fi | |
- name: init | |
run: | | |
gh issue comment ${{ github.event.issue.number }} -b "Hi @${{ github.event.issue.user.login }}, 镜像 ${{ github.event.issue.title }} 正在同步中...<br><br>[详情请查看](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" | |
- name: DockerHub to SWR x86_64 | |
if: contains(github.event.issue.body, 'x86_64') | |
run: | | |
docker login -u cn-south-1@$HUAWEICLOUD_IAM_AK -p $HUAWEICLOUD_IAM_SK swr.cn-south-1.myhuaweicloud.com | |
set -ex | |
images="${{ github.event.issue.title }}" | |
IFS=',' read -r -a image_array <<< "$images" | |
for image in "${image_array[@]}"; do | |
docker pull "${image}" --platform "linux/amd64" | |
docker tag "${image}" swr.cn-south-1.myhuaweicloud.com/gsc-hub/${image}-x86_64 | |
docker push swr.cn-south-1.myhuaweicloud.com/gsc-hub/${image}-x86_64 | |
docker tag "${image}" ${image}-x86_64 | |
echo -n " ${image}-x86_64" >> images.txt | |
done | |
- name: DockerHub to SWR aarch64 | |
if: contains(github.event.issue.body, 'aarch64') | |
run: | | |
docker login -u cn-south-1@$HUAWEICLOUD_IAM_AK -p $HUAWEICLOUD_IAM_SK swr.cn-south-1.myhuaweicloud.com | |
set -ex | |
images="${{ github.event.issue.title }}" | |
IFS=',' read -r -a image_array <<< "$images" | |
for image in "${image_array[@]}"; do | |
docker pull "${image}" --platform "linux/arm64" | |
docker tag "${image}" swr.cn-south-1.myhuaweicloud.com/gsc-hub/${image}-aarch64 | |
docker push swr.cn-south-1.myhuaweicloud.com/gsc-hub/${image}-aarch64 | |
docker tag "${image}" ${image}-aarch64 | |
echo -n " ${image}-aarch64" >> images.txt | |
done | |
- name: Offline images tar gz | |
run: | | |
set -ex | |
docker save $(cat images.txt) | gzip > images.tar.gz | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: images.tar.gz | |
path: images.tar.gz | |
retention-days: 90 # 将保留天数设置为1天 最多可设置90天 | |
- name: success | |
run: | | |
IFS=' ' read -r -a image_name_array <<< "$(cat images.txt)" | |
for image in "${image_name_array[@]}"; do | |
echo "gsc-hub/${image}" >> image_name.txt | |
done | |
gh issue comment ${{ github.event.issue.number }} -b "镜像 ${{ github.event.issue.title }} 同步完成<br><hr>pull时使用域名加上下面的镜像名称:<br><br>$(cat image_name.txt)<br><hr>[离线镜像包下载地址](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" | |
gh issue edit ${{ github.event.issue.number }} --add-label "sync-image-success" | |
gh issue close ${{ github.event.issue.number }} | |
- name: fail | |
if: failure() | |
run: | | |
gh issue comment ${{ github.event.issue.number }} -b "镜像 ${{ github.event.issue.title }} 同步失败<br><br>[失败详情请查看](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" | |
gh issue edit ${{ github.event.issue.number }} --add-label "sync-image-fail" | |
gh issue close ${{ github.event.issue.number }} |