diff --git a/.github/scripts/api_deploy.py b/.github/scripts/api_deploy.py index 058713f..00e7085 100644 --- a/.github/scripts/api_deploy.py +++ b/.github/scripts/api_deploy.py @@ -212,6 +212,13 @@ def create_pr_or_update_branch_on_api_repo( print(f"Switching to branch: {branch_name}") api_repo.git.checkout('-B', branch_name) + # Pull remote branch contents if it exists so we commit on top + try: + api_repo.git.pull('origin', branch_name) + print(f"Pulled latest from origin/{branch_name}") + except GitCommandError: + print(f"No existing remote branch '{branch_name}' to pull.") + # Create repo directory if it doesn't exist repo_dir = os.path.join(temp_dir, repo_name) os.makedirs(repo_dir, exist_ok=True) @@ -250,11 +257,8 @@ def create_pr_or_update_branch_on_api_repo( print("Adding remote 'origin' with access token") origin = api_repo.create_remote("origin", auth_url) - # Force Push because we allow APIs for a specific version to - # reflect the latest representation of the version/ref. print(f"Pushing branch to remote...") - api_repo.git.push('--force', '--set-upstream', - 'origin', branch_name) + api_repo.git.push('--set-upstream', 'origin', branch_name) # Check if PR already exists existing_pr = check_existing_pr( diff --git a/.github/workflows/api_docs_gen.yml b/.github/workflows/api_docs_gen.yml index 58fcc92..4f80c56 100644 --- a/.github/workflows/api_docs_gen.yml +++ b/.github/workflows/api_docs_gen.yml @@ -32,6 +32,9 @@ on: dry_run: type: boolean default: false + api_deploy_version: + type: string + default: 5.x.y jobs: generate_api_docs: @@ -51,7 +54,9 @@ jobs: - run: pip install -r ${{ inputs.dir }}/docs/requirements.txt gitpython requests - run: conan config install https://github.com/libhal/conan-config2.git - run: conan hal docs --doc_version ${{ inputs.version }} ${{ inputs.dir }}/docs - - run: wget https://raw.githubusercontent.com/libhal/ci/5.x.y/.github/scripts/api_deploy.py + - name: print api docs version name + run: echo ${{ inputs.api_deploy_version }} + - run: wget https://raw.githubusercontent.com/libhal/ci/${{ inputs.api_deploy_version }}/.github/scripts/api_deploy.py - name: Deploy to API repo if: ${{ inputs.dry_run == false }} run: python api_deploy.py deploy --version ${{ inputs.version }} --repo-name ${{ inputs.repo_name }} --docs-dir ${{ inputs.dir }}/docs/build/ diff --git a/.github/workflows/self_check.yml b/.github/workflows/self_check.yml index bac5457..600a688 100644 --- a/.github/workflows/self_check.yml +++ b/.github/workflows/self_check.yml @@ -46,6 +46,7 @@ jobs: filters: | api_docs: - '.github/workflows/api_docs_gen.yml' + - '.github/scripts/api_deploy.yml' library_check: - '.github/workflows/library_check.yml' tests: @@ -70,6 +71,7 @@ jobs: dir: . dry_run: true version: main + api_deploy_version: ${{ github.head_ref }} secrets: inherit api_libhal_v4: @@ -82,6 +84,7 @@ jobs: dir: v4 dry_run: true version: main + api_deploy_version: ${{ github.head_ref }} secrets: inherit library_check_libhal_v4: