diff --git a/.github/workflows/updatesource.yml b/.github/workflows/updatesource.yml index 4c64353..7dc4932 100644 --- a/.github/workflows/updatesource.yml +++ b/.github/workflows/updatesource.yml @@ -8,7 +8,6 @@ on: # Add permissions block to ensure the workflow can push changes permissions: contents: write - pull-requests: write jobs: update-source: @@ -16,9 +15,6 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 - with: - ref: main # Explicitly checkout the main branch - fetch-depth: 0 # Fetch all history for proper branching - name: Set up Python uses: actions/setup-python@v4 @@ -38,11 +34,6 @@ jobs: run: | echo "Repository: $GITHUB_REPOSITORY" echo "Event name: $GITHUB_EVENT_NAME" - echo "Event path: $GITHUB_EVENT_PATH" - if [ -f "$GITHUB_EVENT_PATH" ]; then - echo "Event payload:" - cat $GITHUB_EVENT_PATH - fi echo "Current directory: $(pwd)" echo "Repository contents:" ls -la @@ -52,9 +43,14 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - python update_json.py + # Configure git git config --global user.name 'GitHub Action' git config --global user.email 'action@github.com' + + # Run the update script + python update_json.py + + # Check for changes and commit if needed git add repo.json if git diff --staged --quiet; then echo "changes=false" >> $GITHUB_OUTPUT @@ -62,33 +58,12 @@ jobs: else echo "Changes detected in repo.json:" git diff --staged - # Create a new branch for the changes - BRANCH_NAME="update-source-$(date +%Y%m%d-%H%M%S)" - git checkout -b $BRANCH_NAME git commit -m "Updated source with latest StikJIT release" - git push origin $BRANCH_NAME - echo "branch=$BRANCH_NAME" >> $GITHUB_OUTPUT + # Force push to main + git push -f origin HEAD:main echo "changes=true" >> $GITHUB_OUTPUT fi - - name: Create Pull Request - if: steps.update_source.outputs.changes == 'true' - uses: peter-evans/create-pull-request@v5 - with: - token: ${{ secrets.GITHUB_TOKEN }} - branch: ${{ steps.update_source.outputs.branch }} - base: main - title: "Update StikJIT source with latest release" - body: | - This PR updates the repo.json file with the latest StikJIT release information. - - Changes include: - - Updated version information - - Added new release to versions list - - Updated news section - - Please review and merge if everything looks good. - - name: Calculate job duration id: duration if: always() @@ -101,9 +76,9 @@ jobs: run: | if [[ "${{ steps.update_source.outputs.changes }}" == "true" ]]; then echo "## Update StikJIT Source Summary 🚀" >> $GITHUB_STEP_SUMMARY - echo "✅ Changes Detected and Pull Request Created" >> $GITHUB_STEP_SUMMARY + echo "✅ Changes Detected and Pushed" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY - echo "A pull request has been created to update the repo.json file with the latest release information." >> $GITHUB_STEP_SUMMARY + echo "The repo.json file has been updated with the latest release information." >> $GITHUB_STEP_SUMMARY else echo "## Update StikJIT Source Summary 🚀" >> $GITHUB_STEP_SUMMARY echo "🔍 No Changes Detected" >> $GITHUB_STEP_SUMMARY diff --git a/update_json.py b/update_json.py index 707dc2c..5e82508 100644 --- a/update_json.py +++ b/update_json.py @@ -79,12 +79,9 @@ def update_json_file(json_file, latest_release): existing_versions = [v["version"] for v in app["versions"]] print(f"Existing versions: {existing_versions}") - if version in existing_versions: - print(f"Version {version} already exists in the versions list") - # Check if the latest version is already the current version - if version == current_version: - print("The latest version is already the current version, no changes needed") - return False + if version in existing_versions and version == current_version: + print(f"Version {version} already exists and is current, no update needed") + return False version_date = latest_release["published_at"] date_obj = datetime.strptime(version_date, "%Y-%m-%dT%H:%M:%SZ") @@ -120,11 +117,7 @@ def update_json_file(json_file, latest_release): "minOSVersion": "17.4" # Adding minOSVersion for StikJIT } - duplicate_entries = [item for item in app["versions"] if item["version"] == version] - if duplicate_entries: - print(f"Removing duplicate entry for version {version}") - app["versions"].remove(duplicate_entries[0]) - + # Always update with the latest version print(f"Adding new version entry: {version}") app["versions"].insert(0, version_entry)