Skip to content

Commit 768864b

Browse files
Merge branch 'main' into main
2 parents ecd92ae + e87a591 commit 768864b

File tree

4 files changed

+155
-158
lines changed

4 files changed

+155
-158
lines changed

.github/workflows/build-and-review-pr.yml

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838

3939
steps:
4040
- name: Checkout
41-
uses: actions/checkout@v3
41+
uses: actions/checkout@v4
4242
with:
4343
fetch-depth: 0
4444

@@ -103,16 +103,16 @@ jobs:
103103

104104
- name: Checkout
105105
if: env.HAS_CODE_CHANGES == 'true'
106-
uses: actions/checkout@v3
106+
uses: actions/checkout@v4
107107

108108
# -----------------------------------
109109
# Check if action has been recompiled
110110
# -----------------------------------
111-
- name: If action has build step - Setup Node 16.x
112-
uses: actions/setup-node@v3
111+
- name: If action has build step - Setup Node 20.x
112+
uses: actions/setup-node@v4
113113
if: env.HAS_CODE_CHANGES == 'true' && env.HAS_BUILD_STEP == 'true'
114114
with:
115-
node-version: 16.x
115+
node-version: 20.x
116116

117117
- name: If action has build step - Build the action
118118
if: env.HAS_CODE_CHANGES == 'true' && env.HAS_BUILD_STEP == 'true'
@@ -156,7 +156,7 @@ jobs:
156156
- name: Fail the workflow if there are any outstanding changes
157157
if: env.HAS_CODE_CHANGES == 'true' && (env.NEEDS_BUILD_COMMIT == 'true' || env.NEEDS_README_COMMIT == 'true')
158158
id: summary
159-
uses: actions/github-script@v6
159+
uses: actions/github-script@v7
160160
with:
161161
script: |
162162
@@ -224,7 +224,7 @@ jobs:
224224
NEXT_MAJOR_VERSION_NO_PREFIX: ''
225225

226226
# Info for the repo we'll be testing git-version-lite against
227-
TESTING_REPO: 'im-open/internal-repo-for-testing'
227+
TESTING_REPO: 'im-open/internal-repo-for-testing-purple-actions'
228228
TEST_BRANCH: 'my-test-branch'
229229

230230
# These is based on the fetch-depth not being set. git-version-lite starts from 0.0.0 when calculating the next version
@@ -252,16 +252,16 @@ jobs:
252252

253253
- name: Setup - Checkout testing repo in the root directory
254254
if: always()
255-
uses: actions/checkout@v3
255+
uses: actions/checkout@v4
256256
with:
257257
ref: main
258258
repository: ${{ env.TESTING_REPO }}
259259
ssh-key: ${{ secrets.SSH_KEY_TESTING_REPO }}
260-
# fetch-depth: 0 # Do not use this because we want to test what happens when fetch-depth is not set
260+
fetch-depth: 0
261261

262262
- name: Setup - Checkout this action (git-version-lite) into a 'gvl' subdirectory
263263
if: always()
264-
uses: actions/checkout@v3
264+
uses: actions/checkout@v4
265265
with:
266266
path: ./gvl
267267

@@ -326,10 +326,7 @@ jobs:
326326
- name: '-------------------------------------------------------------------------------------------------------'
327327
run: echo ""
328328

329-
- name: When a repo has all of its tags locally
330-
run: git fetch -t
331-
332-
- name: And a new version is requested with fallback-to-no-prefix set
329+
- name: When a new version is requested with fallback-to-no-prefix set
333330
if: always()
334331
uses: ./gvl
335332
id: fallback
@@ -396,7 +393,7 @@ jobs:
396393
NEXT_MAJOR_VERSION_NO_PREFIX: ''
397394

398395
# Info for the repo we'll be testing git-version-lite against
399-
TESTING_REPO: 'im-open/internal-repo-for-testing'
396+
TESTING_REPO: 'im-open/internal-repo-for-testing-purple-actions'
400397
TEST_BRANCH: 'my-test-branch'
401398

402399
# These NEXT tags are set based on the fetch-depth not being set, so
@@ -422,7 +419,7 @@ jobs:
422419

423420
- name: Setup - Checkout testing repo in the root directory
424421
if: always()
425-
uses: actions/checkout@v3
422+
uses: actions/checkout@v4
426423
with:
427424
ref: main
428425
repository: ${{ env.TESTING_REPO }}
@@ -431,7 +428,7 @@ jobs:
431428

432429
- name: Setup - Checkout this action (git-version-lite) into a 'gvl' subdirectory
433430
if: always()
434-
uses: actions/checkout@v3
431+
uses: actions/checkout@v4
435432
with:
436433
path: ./gvl
437434

@@ -598,7 +595,7 @@ jobs:
598595
NEXT_MAJOR_VERSION_NO_PREFIX: ''
599596

600597
# Info for the repo we'll be testing git-version-lite against
601-
TESTING_REPO: 'im-open/internal-repo-for-testing'
598+
TESTING_REPO: 'im-open/internal-repo-for-testing-purple-actions'
602599
TEST_BRANCH: 'my-test-branch'
603600

604601
# All the remaining tags are for TESTING_REPO. If anything changes tag-wise in that repo, these values need to be updated.
@@ -705,7 +702,7 @@ jobs:
705702

706703
- name: Setup - Checkout testing repo in the root directory
707704
if: always()
708-
uses: actions/checkout@v3
705+
uses: actions/checkout@v4
709706
with:
710707
ref: main
711708
repository: ${{ env.TESTING_REPO }}
@@ -714,7 +711,7 @@ jobs:
714711

715712
- name: Setup - Checkout this action (git-version-lite) into a 'gvl' subdirectory
716713
if: always()
717-
uses: actions/checkout@v3
714+
uses: actions/checkout@v4
718715
with:
719716
path: ./gvl
720717

Lines changed: 120 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,120 @@
1-
name: Increment Version on Merge
2-
run-name: "${{ github.event.pull_request.merged && 'Increment version for' || 'Closing' }} PR #${{ github.event.pull_request.number }}"
3-
on:
4-
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
5-
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
6-
#
7-
# GitHub's standard pull_request workflow trigger prevents write permissions and
8-
# secrets access when the PR is from a public fork. PRs from branches and forks of
9-
# internal/private repos are not limited the same way for the pull_request trigger.
10-
#
11-
# The pull_request_target trigger (which this workflow is using) relaxes some of those
12-
# restrictions and allows PRs from public forks to have write permissions through the
13-
# GH_TOKEN which we need in order to push new tags to the repo through this workflow.
14-
#
15-
# For this workflow, the elevated permissions should not be a problem because:
16-
# • This workflow is only triggered when a PR is closed and the reusable workflow it
17-
# calls only executes if it has been merged to the default branch. This means the PR
18-
# has been reviewed and approved by a CODEOWNER and merged by someone with Write
19-
# access before this workflow with its elevated permissions gets executed. Any code
20-
# that doesn't meet our standards should be caught before it gets to this point.
21-
# • The "Require approval for all outside collaborators" setting is set at the org-level.
22-
# Before a workflow can execute for a PR generated by an outside collaborator, a user
23-
# with Write access must manually approve the request to execute the workflow run.
24-
# Prior to doing so they should have had a chance to review any changes in the PR
25-
pull_request_target:
26-
types: [closed]
27-
# paths:
28-
# Do not include specific paths here. reusable-increment-version-on-merge.yml will decide
29-
# if this action should be incremented and if new tags should be pushed to the repo based
30-
# on the same criteria used in the build-and-review-pr.yml workflow.
31-
32-
33-
# ------------------------------------------------------------------------------------
34-
# NOTE: This repo duplicates the reusable increment workflow in im-open/.github that
35-
# the rest of the actions use. If changes are needed in this workflow they
36-
# should also be made in im-open/.github. This workflow is duplicated because
37-
# it uses the local copy of itself in the workflow which allows us to test the
38-
# increment build with git-version-lite changes before we merge those changes.
39-
# ------------------------------------------------------------------------------------
40-
41-
jobs:
42-
increment-version:
43-
runs-on: ubuntu-latest
44-
env:
45-
MERGE_TO_MAIN: 'false'
46-
47-
steps:
48-
- name: Check if merge to default branch
49-
id: merge
50-
uses: actions/github-script@v6
51-
with:
52-
script: |
53-
const defaultBranch = 'main';
54-
const baseRef = '${{ github.event.pull_request.base.ref }}';
55-
const merged = ${{ github.event.pull_request.merged }};
56-
57-
if (!merged){
58-
console.log('PR is not merged. Skipping subsequent steps.');
59-
core.exportVariable('MERGE_TO_MAIN', false);
60-
return;
61-
}
62-
if (baseRef !== defaultBranch){
63-
console.log(`PR is merged to ${baseRef} and not ${defaultBranch}. Skipping subsequent steps.`);
64-
core.exportVariable('MERGE_TO_MAIN', false);
65-
return;
66-
}
67-
console.log(`PR is merged to ${defaultBranch}. Proceed with subsequent steps.`);
68-
core.exportVariable('MERGE_TO_MAIN', true);
69-
70-
- name: Checkout
71-
if: env.MERGE_TO_MAIN == 'true'
72-
uses: actions/checkout@v3
73-
74-
- name: If PR is merged to main - Check for code changes to the action source code
75-
if: env.MERGE_TO_MAIN == 'true'
76-
id: source-code
77-
uses: im-open/did-custom-action-code-change@v1
78-
with:
79-
files-with-code: 'action.yml,package.json,package-lock.json'
80-
folders-with-code: 'src,dist'
81-
token: ${{ secrets.GITHUB_TOKEN }}
82-
83-
- name: If PR is merged to main - Print whether Action Source Code Changed (open for details)
84-
if: env.MERGE_TO_MAIN == 'true'
85-
run: |
86-
if [ "${{ steps.source-code.outputs.HAS_CHANGES }}" == "true" ]; then
87-
echo "This PR changes the action's source code. Proceed with subsequent steps."
88-
else
89-
echo "This PR does not change the action's source code. Skipping subsequent steps."
90-
fi
91-
92-
- name: If PR is merged to main & PR has source code changes - Checkout
93-
if: env.MERGE_TO_MAIN == 'true' && steps.source-code.outputs.HAS_CHANGES == 'true'
94-
uses: actions/checkout@v3
95-
with:
96-
ref: main
97-
fetch-depth: 0
98-
99-
- name: If PR is merged to main & PR has source code changes - Get the next version for the repo
100-
if: env.MERGE_TO_MAIN == 'true' && steps.source-code.outputs.HAS_CHANGES == 'true'
101-
id: version
102-
uses: ./
103-
104-
- name: If PR is merged to main & PR has source code changes - Print action version (${{ steps.version.outputs.NEXT_VERSION || 'N/A'}})
105-
if: env.MERGE_TO_MAIN == 'true' && steps.source-code.outputs.HAS_CHANGES == 'true'
106-
run: echo "The next action version will be - ${{ steps.version.outputs.NEXT_VERSION }}"
107-
108-
- name: If PR is merged to main & PR has source code changes - Push tags to repo
109-
if: env.MERGE_TO_MAIN == 'true' && steps.source-code.outputs.HAS_CHANGES == 'true'
110-
run: |
111-
git config user.name github-actions
112-
git config user.email github-actions@github.com
113-
114-
git tag ${{ steps.version.outputs.NEXT_VERSION }} ${{ github.sha }}
115-
git tag -f ${{ steps.version.outputs.NEXT_MAJOR_VERSION }} ${{ github.sha }}
116-
git tag -f ${{ steps.version.outputs.NEXT_MINOR_VERSION }} ${{ github.sha }}
117-
118-
git push origin ${{ steps.version.outputs.NEXT_VERSION }}
119-
git push origin ${{ steps.version.outputs.NEXT_MAJOR_VERSION }} -f
120-
git push origin ${{ steps.version.outputs.NEXT_MINOR_VERSION }} -f
1+
name: Increment Version on Merge
2+
run-name: "${{ github.event.pull_request.merged && 'Increment version for' || 'Closing' }} PR #${{ github.event.pull_request.number }}"
3+
on:
4+
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
5+
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
6+
#
7+
# GitHub's standard pull_request workflow trigger prevents write permissions and
8+
# secrets access when the PR is from a public fork. PRs from branches and forks of
9+
# internal/private repos are not limited the same way for the pull_request trigger.
10+
#
11+
# The pull_request_target trigger (which this workflow is using) relaxes some of those
12+
# restrictions and allows PRs from public forks to have write permissions through the
13+
# GH_TOKEN which we need in order to push new tags to the repo through this workflow.
14+
#
15+
# For this workflow, the elevated permissions should not be a problem because:
16+
# • This workflow is only triggered when a PR is closed and the reusable workflow it
17+
# calls only executes if it has been merged to the default branch. This means the PR
18+
# has been reviewed and approved by a CODEOWNER and merged by someone with Write
19+
# access before this workflow with its elevated permissions gets executed. Any code
20+
# that doesn't meet our standards should be caught before it gets to this point.
21+
# • The "Require approval for all outside collaborators" setting is set at the org-level.
22+
# Before a workflow can execute for a PR generated by an outside collaborator, a user
23+
# with Write access must manually approve the request to execute the workflow run.
24+
# Prior to doing so they should have had a chance to review any changes in the PR
25+
pull_request_target:
26+
types: [closed]
27+
# paths:
28+
# Do not include specific paths here. reusable-increment-version-on-merge.yml will decide
29+
# if this action should be incremented and if new tags should be pushed to the repo based
30+
# on the same criteria used in the build-and-review-pr.yml workflow.
31+
32+
33+
# ------------------------------------------------------------------------------------
34+
# NOTE: This repo duplicates the reusable increment workflow in im-open/.github that
35+
# the rest of the actions use. If changes are needed in this workflow they
36+
# should also be made in im-open/.github. This workflow is duplicated because
37+
# it uses the local copy of itself in the workflow which allows us to test the
38+
# increment build with git-version-lite changes before we merge those changes.
39+
# ------------------------------------------------------------------------------------
40+
41+
jobs:
42+
increment-version:
43+
runs-on: ubuntu-latest
44+
env:
45+
MERGE_TO_MAIN: 'false'
46+
47+
steps:
48+
- name: Check if merge to default branch
49+
id: merge
50+
uses: actions/github-script@v7
51+
with:
52+
script: |
53+
const defaultBranch = 'main';
54+
const baseRef = '${{ github.event.pull_request.base.ref }}';
55+
const merged = ${{ github.event.pull_request.merged }};
56+
57+
if (!merged){
58+
console.log('PR is not merged. Skipping subsequent steps.');
59+
core.exportVariable('MERGE_TO_MAIN', false);
60+
return;
61+
}
62+
if (baseRef !== defaultBranch){
63+
console.log(`PR is merged to ${baseRef} and not ${defaultBranch}. Skipping subsequent steps.`);
64+
core.exportVariable('MERGE_TO_MAIN', false);
65+
return;
66+
}
67+
console.log(`PR is merged to ${defaultBranch}. Proceed with subsequent steps.`);
68+
core.exportVariable('MERGE_TO_MAIN', true);
69+
70+
- name: Checkout
71+
if: env.MERGE_TO_MAIN == 'true'
72+
uses: actions/checkout@v4
73+
74+
- name: If PR is merged to main - Check for code changes to the action source code
75+
if: env.MERGE_TO_MAIN == 'true'
76+
id: source-code
77+
uses: im-open/did-custom-action-code-change@v1
78+
with:
79+
files-with-code: 'action.yml,package.json,package-lock.json'
80+
folders-with-code: 'src,dist'
81+
token: ${{ secrets.GITHUB_TOKEN }}
82+
83+
- name: If PR is merged to main - Print whether Action Source Code Changed (open for details)
84+
if: env.MERGE_TO_MAIN == 'true'
85+
run: |
86+
if [ "${{ steps.source-code.outputs.HAS_CHANGES }}" == "true" ]; then
87+
echo "This PR changes the action's source code. Proceed with subsequent steps."
88+
else
89+
echo "This PR does not change the action's source code. Skipping subsequent steps."
90+
fi
91+
92+
- name: If PR is merged to main & PR has source code changes - Checkout
93+
if: env.MERGE_TO_MAIN == 'true' && steps.source-code.outputs.HAS_CHANGES == 'true'
94+
uses: actions/checkout@v4
95+
with:
96+
ref: main
97+
fetch-depth: 0
98+
99+
- name: If PR is merged to main & PR has source code changes - Get the next version for the repo
100+
if: env.MERGE_TO_MAIN == 'true' && steps.source-code.outputs.HAS_CHANGES == 'true'
101+
id: version
102+
uses: ./
103+
104+
- name: If PR is merged to main & PR has source code changes - Print action version (${{ steps.version.outputs.NEXT_VERSION || 'N/A'}})
105+
if: env.MERGE_TO_MAIN == 'true' && steps.source-code.outputs.HAS_CHANGES == 'true'
106+
run: echo "The next action version will be - ${{ steps.version.outputs.NEXT_VERSION }}"
107+
108+
- name: If PR is merged to main & PR has source code changes - Push tags to repo
109+
if: env.MERGE_TO_MAIN == 'true' && steps.source-code.outputs.HAS_CHANGES == 'true'
110+
run: |
111+
git config user.name github-actions
112+
git config user.email github-actions@github.com
113+
114+
git tag ${{ steps.version.outputs.NEXT_VERSION }} ${{ github.sha }}
115+
git tag -f ${{ steps.version.outputs.NEXT_MAJOR_VERSION }} ${{ github.sha }}
116+
git tag -f ${{ steps.version.outputs.NEXT_MINOR_VERSION }} ${{ github.sha }}
117+
118+
git push origin ${{ steps.version.outputs.NEXT_VERSION }}
119+
git push origin ${{ steps.version.outputs.NEXT_MAJOR_VERSION }} -f
120+
git push origin ${{ steps.version.outputs.NEXT_MINOR_VERSION }} -f

0 commit comments

Comments
 (0)