Skip to content

Commit 2762b2e

Browse files
authored
Merge pull request Mellanox#132 from heyvister1/fix-docs-ci-triggers
Fixing docs-ci workflow triggers
2 parents bd62c8d + 6f9ef41 commit 2762b2e

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

.github/workflows/docs-ci.yaml

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,25 @@ on:
66
git_tag:
77
type: string
88
description: The git tag (version) from the calling workflow
9-
required: true
9+
1010
workflow_dispatch:
1111
inputs:
1212
git_tag:
1313
type: string
1414
description: The git tag (version) to use for `$TAG`
15-
required: true
1615

1716
jobs:
1817
docs-ci:
1918
runs-on: ubuntu-latest
2019
env:
2120
GH_TOKEN: ${{ secrets.GH_TOKEN_NVIDIA_CI_CD }}
21+
# keeping TAG for cases docs repo workflow is triggered with tag input
2222
TAG: ${{ inputs.git_tag }}
23+
REF_NAME: ${{ github.ref_name }}
24+
# in case of pushed PR, ref_head specifies PR's branch
25+
REF_HEAD: ${{ github.head_ref }}
26+
# will be used to specify repo tar url according to PR id
27+
PR_NUMBER: ${{ github.event.number }}
2328
PR_TITLE_PREFIX: "task: update documentation for"
2429
steps:
2530
- uses: actions/checkout@v4
@@ -31,7 +36,19 @@ jobs:
3136
with:
3237
go-version: 1.23.x
3338
- name: Make docs
39+
# handle triggered workflow by pushed tag or PR
3440
run: |
41+
if [[ -n $PR_NUMBER ]]; then
42+
export BRANCH=$REF_HEAD
43+
echo "REF_NAME=$REF_HEAD" >> $GITHUB_ENV
44+
echo "COMMIT_SUFFIX=pull/$PR_NUMBER" >> $GITHUB_ENV
45+
else
46+
TAG="${TAG:-$REF_NAME}"
47+
export TAG
48+
echo "TAG=$TAG" >> $GITHUB_ENV
49+
echo "COMMIT_SUFFIX=$TAG" >> $GITHUB_ENV
50+
fi
51+
3552
make api-docs helm-docs generate-docs-versions-var
3653
- name: Close any existing documentation PRs
3754
run: |
@@ -40,23 +57,22 @@ jobs:
4057
done
4158
- name: Create PR
4259
env:
60+
REF_NAME: ${{ github.ref_name }}
4361
DOWNSTREAM_REPO_OWNER: nvidia-ci-cd
44-
DOWNSTREAM_FEATURE_BRANCH: update-docs-for-${{ env.TAG }}
62+
DOWNSTREAM_FEATURE_BRANCH: update-docs-for-${{ env.REF_NAME }}
4563
UPSTREAM_REPO_OWNER: Mellanox
4664
UPSTREAM_DEFAULT_BRANCH: main
47-
COMMIT_MESSAGE: ${{ env.PR_TITLE_PREFIX }} ${{ env.TAG }}
4865
run: |
49-
git config user.name nvidia-ci-cd
66+
git config user.name nvidia-ci-cd
5067
git config user.email [email protected]
5168
gh repo fork --remote --default-branch-only
5269
gh repo sync $DOWNSTREAM_REPO_OWNER/network-operator-docs --source $UPSTREAM_REPO_OWNER/network-operator-docs --branch $UPSTREAM_DEFAULT_BRANCH
53-
5470
git checkout -b $DOWNSTREAM_FEATURE_BRANCH
55-
git status
5671
git add docs
72+
COMMIT_MESSAGE="$PR_TITLE_PREFIX $COMMIT_SUFFIX"
5773
git commit -m "$COMMIT_MESSAGE"
5874
59-
git push -u origin $DOWNSTREAM_FEATURE_BRANCH
75+
git push -u origin $DOWNSTREAM_FEATURE_BRANCH --force
6076
gh pr create \
6177
--head $DOWNSTREAM_REPO_OWNER:$DOWNSTREAM_FEATURE_BRANCH \
6278
--base $UPSTREAM_DEFAULT_BRANCH \

Makefile

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,23 @@ export PATH:=$(GOBIN):${PATH}
1313

1414
BRANCH ?= master
1515
TAG ?=
16-
# Then using TAG, the tar file starts with v, but the extracted dir does not
17-
SRC := $(shell echo $(if $(TAG),$(TAG),$(BRANCH)) | sed 's/^v//')
16+
# Handling the following use cases for repo url:
17+
# 1. PR - refs/pull/<PR id>
18+
# 2. TAG - refs/<tag name (omitted 'v' prefix in url)>
19+
# 3. BRANCH - refs/<branch name>
20+
ifdef PR_NUMBER
21+
SRC = refs-pull-$(PR_NUMBER)-head
22+
REFS_NAME = pull/$(PR_NUMBER)
23+
else ifdef TAG
24+
SRC = $(shell echo $(TAG) | sed 's/^v//')
25+
REFS_NAME=tags/$(TAG)
26+
else
27+
SRC = $(BRANCH)
28+
REFS_NAME=$(BRANCH)
29+
endif
1830

1931
# Network Operator source tar location
20-
REPO_TAR_URL ?= https://github.com/Mellanox/network-operator/archive/refs/$(if $(TAG),tags/$(TAG),heads/$(BRANCH)).tar.gz
32+
REPO_TAR_URL ?= https://github.com/Mellanox/network-operator/archive/refs/$(REFS_NAME)/head.tar.gz
2133
# release.yaml location
2234
RELEASE_YAML_URL ?= https://raw.githubusercontent.com/Mellanox/network-operator/$(if $(TAG),$(TAG),$(BRANCH))/hack/release.yaml
2335

0 commit comments

Comments
 (0)