From 826c7d738d3529208939312446d8c1ef0d848a84 Mon Sep 17 00:00:00 2001 From: LamGC Date: Sat, 18 Mar 2023 23:26:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E7=94=A8=E8=84=9A=E6=9C=AC=E6=9D=A5?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E4=BA=86=EF=BC=8C=E4=B8=80=E8=84=9A=E8=B8=A2?= =?UTF-8?q?=E5=BC=80=20github-scripts=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/check-updates.yml | 27 ++++++++++----------------- update-version.sh | 4 ++++ 2 files changed, 14 insertions(+), 17 deletions(-) create mode 100644 update-version.sh diff --git a/.github/workflows/check-updates.yml b/.github/workflows/check-updates.yml index 518e450..305dcf4 100644 --- a/.github/workflows/check-updates.yml +++ b/.github/workflows/check-updates.yml @@ -9,26 +9,19 @@ permissions: contents: write jobs: - # 检查 jenkinsci/docker-inbound-agent 仓库的最新版本,并将最新版本写入到 LATEST_VERSION 文件中 + # 检查 jenkinsci/docker-inbound-agent 仓库的最新版本,并使用 actions/github-script 向 LATEST_VERSION 文件写入最新版本号。 check-updates: - timeout-minutes: 5 + timeout-minutes: 30 runs-on: ubuntu-latest + steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Check updates - uses: actions/github-script@v5 + run: chmod +x ./update-version.sh && ./update-version.sh + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v4 with: - script: | - const { data: { tag_name: latestVersion } } = await github.repos.getLatestRelease({ - owner: 'jenkinsci', - repo: 'docker-inbound-agent', - }); - await github.repos.createOrUpdateFileContents({ - owner: context.repo.owner, - repo: context.repo.repo, - path: 'LATEST_VERSION', - message: `Update LATEST_VERSION to ${latestVersion}`, - content: Buffer.from(latestVersion).toString(), - sha: context.sha, - }); \ No newline at end of file + commit_message: Update LATEST_VERSION + commit_options: '--no-verify' + file_pattern: LATEST_VERSION \ No newline at end of file diff --git a/update-version.sh b/update-version.sh new file mode 100644 index 0000000..16ea024 --- /dev/null +++ b/update-version.sh @@ -0,0 +1,4 @@ +LATEST_VERSION=$(curl -s https://api.github.com/repos/jenkinsci/docker-inbound-agent/releases/latest | grep tag_name | cut -d '"' -f 4) +if [ "$LATEST_VERSION" != "$(cat LATEST_VERSION)" ]; then + echo "$LATEST_VERSION" > LATEST_VERSION +fi \ No newline at end of file