-
Notifications
You must be signed in to change notification settings - Fork 6
54 lines (52 loc) · 2.39 KB
/
target_sync_image.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
name: Target Sync Image
on:
issues:
types: [opened, edited]
workflow_dispatch:
permissions:
issues: write
jobs:
sync:
runs-on: ubuntu-24.04
permissions:
issues: write
if: contains(github.event.issue.labels.*.name, 'porter')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check Issue
run: |
gh auth login --with-token <<< ${{ secrets.GITHUB_TOKEN }}
ORIGIN_IMAGE=$(echo "${{ github.event.issue.title }}" | awk '{print $1}')
if [[ -z "${ORIGIN_IMAGE}" ]]; then
gh issue comment ${{ github.event.issue.number }} -b "Image not found."
exit 1
fi
if [[ "${ORIGIN_IMAGE}" != *":"* ]]; then
gh issue comment ${{ github.event.issue.number }} -b "镜像 ${ORIGIN_IMAGE} 不存在, 请指定 tag, 如: ${ORIGIN_IMAGE}:latest"
exit 1
fi
if [[ "${ORIGIN_IMAGE%%/*}" != *"."* ]]; then
gh issue comment ${{ github.event.issue.number }} -b "镜像 ${ORIGIN_IMAGE} 不存在, 请指定域名, 如: docker.io/${ORIGIN_IMAGE}"
exit 1
fi
- name: Sync image
env:
DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }}
DOCKER_USER: ${{ secrets.DOCKER_USER }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_NAMESPACE: ${{ secrets.DOCKER_NAMESPACE }}
SKOPEO_INSECURE: ${{ env.SKOPEO_INSECURE }}
run: |
gh auth login --with-token <<< ${{ secrets.GITHUB_TOKEN }}
ORIGIN_IMAGE=$(echo "${{ github.event.issue.title }}" | awk '{print $1}')
IMAGE_NAME=$(echo "${{ github.event.issue.title }}" | awk -F'/' '{print $NF}')
bash ./hack/target_sync_image.sh "$ORIGIN_IMAGE" "$DOCKER_REGISTRY/$DOCKER_NAMESPACE"
gh issue comment ${{ github.event.issue.number }} -b "镜像 ${ORIGIN_IMAGE} 同步完成<br>请使用 $DOCKER_REGISTRY/$DOCKER_NAMESPACE/$IMAGE_NAME 下载"
gh issue close ${{ github.event.issue.number }} --reason "completed"
- name: Fail Sync
if: failure()
run: |
ORIGIN_IMAGE=$(echo ${{ github.event.issue.title }} | awk '{print $1}')
gh issue comment ${{ github.event.issue.number }} -b "镜像 ${ORIGIN_IMAGE} 同步失败[详情请查看](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})<br>请检查 image 是否存在"
gh issue close ${{ github.event.issue.number }} --reason "completed"