[image-syncer] 同步任务 #125
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
# This is a basic workflow to help you get started with Actions | |
name: image-sync | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
schedule: | |
- cron: '0 14 * * 1' | |
issues: | |
types: | |
- opened | |
env: | |
IMAGE_SYNCER_VERSION: v1.3.1 | |
USERNAME: ${{ secrets.ALIYUN_USERNAME }} | |
PASSWORD: ${{ secrets.ALIYUN_PASSWORD }} | |
ORIGIN_ISSUSE_BODY: ${{ github.event.issue.body }} | |
jobs: | |
image-sync: | |
runs-on: ubuntu-latest | |
if: contains(github.event.issue.labels.*.name, 'image-syncer') | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: install image-sync tool | |
run: | | |
wget https://github.com/AliyunContainerService/image-syncer/releases/download/${IMAGE_SYNCER_VERSION}/image-syncer-${IMAGE_SYNCER_VERSION}-linux-amd64.tar.gz | |
tar -zxf image-syncer-${IMAGE_SYNCER_VERSION}-linux-amd64.tar.gz | |
- name: format registry name | |
run: | | |
new_body=$(echo ${{github.event.issue.body}} | sed 's/\//./g;s/^\s*//;s/\s*$//') | |
echo "ISSUSE_BODY=$new_body" >> $GITHUB_ENV | |
- name: add sercret to file | |
run: envsubst < config_source.yaml > config.yaml | |
- name: cat file | |
run: cat config.yaml | |
- name: sync images | |
id: sync_images | |
run: ./image-syncer --proc=10 --config=config.yaml --retries=2 | |
- name: Success comment | |
if: ${{ success() }} | |
uses: actions/github-script@v5 | |
with: | |
script: | | |
const body = `同步成功,拉取命令如下\n\n\`\`\`shell\ndocker pull registry.cn-shenzhen.aliyuncs.com/os_mirror/${{ env.ISSUSE_BODY }}\n\`\`\`\n` | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: body | |
}) | |
github.rest.issues.addLabels({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
labels: ['success'] | |
}) | |
- name: Failure issues | |
if: ${{ failure() }} | |
uses: actions/github-script@v5 | |
with: | |
script: | | |
const body = "[构建失败,点击查看](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" | |
github.rest.issues.addLabels({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
labels: ['failure'] | |
}) | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: body | |
}) |