Skip to content
This repository has been archived by the owner on Aug 31, 2024. It is now read-only.

Commit

Permalink
ci: 新增驗證測試版是否存在 (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
xMikux authored Aug 31, 2023
1 parent 3390f0b commit b3184fb
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
34 changes: 34 additions & 0 deletions .github/scripts/modrinth_verify_exist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import os
import sys
import json
import requests

def main(version):
modrinth_api = f"https://api.modrinth.com/v2/project/cF5VXmkW/version/{version}"
github_project = os.environ["GITHUB_REPOSITORY"]
headers = {"User-Agent": f"{github_project} (Verify Exist Script)"}

response = requests.get(modrinth_api, headers=headers)

if response.status_code == 200:
json_data = json.loads(response.text)
version_number = json_data["version_number"]
date_published = json_data["date_published"]

# Set step output
with open(os.environ["GITHUB_OUTPUT"], "w") as f:
f.write("version_exist=true")

# Print a warning message
print(f"::warning::版本 {version_number} 已存在!發佈時間 {date_published}。")
else:
print("版本未存在!")
# Set step output
with open(os.environ["GITHUB_OUTPUT"], "w") as f:
f.write("version_exist=false")

if __name__ == "__main__":
git_version = sys.argv[1]
if len(sys.argv) < 2:
sys.exit(1)
main(git_version)
11 changes: 9 additions & 2 deletions .github/workflows/CI-Pack-Beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ jobs:
MSG=$(git show -s --format=%s)
echo "msg=$MSG" >> "$GITHUB_OUTPUT"
verify-exist:
name: Verify Version Exist
if: github.repository == 'xMikux/ModsTranslationPack'

uses: ./.github/workflows/Reusable-VerifyExistVersion.yml

pack-beta:
name: Pack ${{ matrix.version }}
needs: [ matrix-setup ]
Expand All @@ -59,12 +65,13 @@ jobs:

modrinth-publish:
name: Modrinth Beta ${{ matrix.version }}
needs: [ pack-beta, matrix-setup, changelog-commit ]
needs: [ pack-beta, matrix-setup, changelog-commit, verify-exist ]
if: ${{ needs.verify-exist.outputs.version_exist != 'true' }}

strategy:
max-parallel: 1
matrix: ${{ fromJson(needs.matrix-setup.outputs.matrix) }}

uses: ./.github/workflows/Reusable-ModrinthPublish.yml
with:
matrix_version: ${{ matrix.version }}
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/Reusable-VerifyExistVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Reusable | Verify Exist Version

on:
workflow_call:
outputs:
version_exist:
description: "Version Exist"
value: ${{ jobs.verify_exist.outputs.version_exist }}

jobs:
verify_exist:
name: Verify Version Exist
runs-on: ubuntu-latest

outputs:
version_exist: ${{ steps.verify.outputs.version_exist }}

steps:
- name: Checking Repository
uses: actions/checkout@v3

- name: Check version exist
id: verify
run: |
GIT_VERSION=git-$(git rev-parse --short HEAD)
python .github/scripts/modrinth_verify_exist.py $GIT_VERSION

0 comments on commit b3184fb

Please sign in to comment.