Skip to content

Commit 0a700f5

Browse files
committed
Update GitHub Actions workflow for doc-detective-common
- Change checkout action to version 4 - Set version variable from inputs or payload - Install specific version of doc-detective-common - Add steps to commit changes if there are any - Bump patch version and create a release if changes are committed
1 parent a02221d commit 0a700f5

File tree

1 file changed

+55
-5
lines changed

1 file changed

+55
-5
lines changed

.github/workflows/update-common.yml

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
version:
1010
description: 'The doc-detective-common version.'
1111
required: false
12+
default: 'latest'
1213

1314
jobs:
1415
update:
@@ -17,13 +18,62 @@ jobs:
1718
runs-on: ubuntu-latest
1819
steps:
1920
- name: Checkout code
20-
uses: actions/checkout@v3
21+
uses: actions/checkout@v4
22+
with:
23+
token: ${{ secrets.DD_DEP_UPDATE_TOKEN }}
24+
25+
- name: Set version variable
26+
id: version
27+
run: |
28+
VERSION="${{ github.event.client_payload.version || github.event.inputs.version || 'latest' }}"
29+
echo "version=$VERSION" >> $GITHUB_OUTPUT
30+
echo "Using version: $VERSION"
31+
32+
- name: Configure Git
33+
run: |
34+
git config --local user.email "[email protected]"
35+
git config --local user.name "GitHub Action"
2136
2237
- name: Install specific version of doc-detective-common
2338
run: |
24-
npm install doc-detective-common@${{ github.event.client_payload.version || github.event.inputs.version }}
39+
npm install doc-detective-common@${{ steps.version.outputs.version }} || {
40+
echo "Failed to install doc-detective-common@${{ steps.version.outputs.version }}"
41+
exit 1
42+
}
43+
44+
- name: Test the installation
45+
run: |
46+
npm test
47+
48+
- name: Commit changes
49+
id: commit
50+
run: |
51+
git add package.json package-lock.json
52+
if git diff --staged --quiet; then
53+
echo "No changes to commit"
54+
echo "has_changes=false" >> $GITHUB_OUTPUT
55+
else
56+
git commit -m "chore: bump doc-detective-common version to ${{ steps.version.outputs.version }}"
57+
git push
58+
echo "has_changes=true" >> $GITHUB_OUTPUT
59+
fi
60+
61+
- name: Bump patch version
62+
id: patch
63+
if: steps.commit.outputs.has_changes == 'true'
64+
run: |
65+
npm version patch
66+
git push
67+
git push --tags
68+
echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
2569
26-
- name: Regenerate references
27-
run: npm i
70+
- name: Create release
71+
if: steps.commit.outputs.has_changes == 'true'
72+
uses: softprops/action-gh-release@v2
73+
with:
74+
body: "Updated doc-detective-common to v${{ steps.patch.outputs.version }}."
75+
tag_name: "v${{ steps.patch.outputs.version }}"
76+
name: "v${{ steps.patch.outputs.version }}"
77+
generate_release_notes: true
78+
token: ${{ secrets.DD_DEP_UPDATE_TOKEN }}
2879

29-
- uses: stefanzweifel/git-auto-commit-action@v4

0 commit comments

Comments
 (0)