Skip to content

Commit d42fc41

Browse files
dshevtsovCopilot
andauthored
Add GH workflows to automate adding pull requests and issues to organizational projects and convert the PR validation workflow to reusable (#196)
* Add GitHub Actions workflows to automate adding pull requests and issues to organizational projects. Introduce this in the reusable workflow form to be able to use from from other projects to avoid code duplication. * Fix PR Comment workflow when remark-lint was skipped * Upload lint results for skipped validation * Use pull_request_target event to allow forked PRs to be added to GH Projects * Convert PR validation to reusable workflow for calling from other repositories * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add required GitHub token for project automation in reusable workflow and update workflow reference to local path --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent ab926c2 commit d42fc41

File tree

5 files changed

+81
-6
lines changed

5 files changed

+81
-6
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
##### Aggregate Commerce PRs and Issues into a respective Organizational Project #####
2+
3+
name: Add pull requests and issues to projects
4+
5+
on:
6+
pull_request_target:
7+
types:
8+
- opened
9+
issues:
10+
types:
11+
- opened
12+
13+
jobs:
14+
call-workflow-add-to-project:
15+
uses: ./.github/workflows/add-to-project_job.yml
16+
secrets: inherit
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Add to project job
2+
3+
on:
4+
workflow_call:
5+
secrets:
6+
COMMERCE_PROJECT_AUTOMATION:
7+
description: 'GitHub token for project automation'
8+
required: true
9+
10+
jobs:
11+
add-to-project:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Add to Commerce PR project
16+
if: github.event_name == 'pull_request_target'
17+
uses: actions/add-to-project@v1.0.2
18+
with:
19+
project-url: https://github.com/orgs/AdobeDocs/projects/5 # The organizational project for pull requests
20+
github-token: ${{ secrets.COMMERCE_PROJECT_AUTOMATION }}
21+
22+
- name: Add to Commerce Issue project
23+
if: github.event_name == 'issues'
24+
uses: actions/add-to-project@v1.0.2
25+
with:
26+
project-url: https://github.com/orgs/AdobeDocs/projects/6 # The organizational project for issues
27+
github-token: ${{ secrets.COMMERCE_PROJECT_AUTOMATION }}

.github/workflows/pr-comment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name: PR Comment
33
on:
44
workflow_run:
5-
workflows: ["Validate pull request"]
5+
workflows: ["PR validation"]
66
types:
77
- completed
88

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
name: PR validation
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
validate:
8+
uses: ./.github/workflows/validate-pr.yml
9+
with:
10+
pr_number: ${{ github.event.pull_request.number }}
11+
base_ref: ${{ github.event.pull_request.base.ref }}
12+

.github/workflows/validate-pr.yml

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
---
22
name: Validate pull request
33
on:
4-
pull_request:
4+
workflow_call:
5+
inputs:
6+
pr_number:
7+
description: 'Pull request number'
8+
required: true
9+
type: number
10+
base_ref:
11+
description: 'Base branch reference'
12+
required: true
13+
type: string
514

615
jobs:
716
# Check if src/pages files were changed
@@ -18,8 +27,8 @@ jobs:
1827
- name: Check for src/pages changes
1928
id: filter
2029
run: |
21-
git fetch origin ${{ github.base_ref }}
22-
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)
30+
git fetch origin ${{ inputs.base_ref }}
31+
CHANGED_FILES=$(git diff --name-only origin/${{ inputs.base_ref }}...HEAD)
2332
if echo "$CHANGED_FILES" | grep -q "^src/pages/"; then
2433
echo "run_validation=true" >> $GITHUB_OUTPUT
2534
echo "✅ Changes detected in src/pages/"
@@ -99,7 +108,7 @@ jobs:
99108
100109
# Save warning status for the comment workflow
101110
echo "true" > has-warnings.txt
102-
echo "${{ github.event.pull_request.number }}" > pr-number.txt
111+
echo "${{ inputs.pr_number }}" > pr-number.txt
103112
else
104113
echo "✅ **No issues found!**" >> $GITHUB_STEP_SUMMARY
105114
echo "" >> $GITHUB_STEP_SUMMARY
@@ -108,7 +117,7 @@ jobs:
108117
109118
# Save no-warning status
110119
echo "false" > has-warnings.txt
111-
echo "${{ github.event.pull_request.number }}" > pr-number.txt
120+
echo "${{ inputs.pr_number }}" > pr-number.txt
112121
fi
113122
114123
- name: Upload lint results
@@ -131,6 +140,8 @@ jobs:
131140
# If no src/pages files changed, pass automatically
132141
if [[ "${{ needs.check-files.outputs.run_validation }}" == "false" ]]; then
133142
echo "✅ No src/pages/ files changed - validation skipped"
143+
echo "false" > has-warnings.txt
144+
echo "${{ inputs.pr_number }}" > pr-number.txt
134145
exit 0
135146
fi
136147
@@ -147,3 +158,12 @@ jobs:
147158
echo "Remark Lint: ${{ needs.remark-lint.result }}"
148159
exit 1
149160
fi
161+
162+
- name: Upload lint results for skipped validation
163+
if: needs.check-files.outputs.run_validation == 'false'
164+
uses: actions/upload-artifact@v4
165+
with:
166+
name: lint-results
167+
path: |
168+
has-warnings.txt
169+
pr-number.txt

0 commit comments

Comments
 (0)