Skip to content

Commit fe036d6

Browse files
committed
chore(actions): add auto commit in cd
1 parent b77c4eb commit fe036d6

File tree

1 file changed

+75
-2
lines changed

1 file changed

+75
-2
lines changed

.github/workflows/cd.yml

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,83 @@ name: CD
22

33
on:
44
release:
5-
types: [ published ]
5+
types: [published]
66

77
jobs:
88
refresh:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: siyul-park/notify-pkg-go-dev@v1
11+
- run: |
12+
# Parameters from the Action inputs
13+
BASE_URL="https://pkg.go.dev/fetch"
14+
REPO_URL="github.com/${{ github.repository }}"
15+
RELEASE_TAG="${{ github.event.release.tag_name }}"
16+
17+
# If the tag contains '/', replace the last '/' with '@'
18+
if [[ "$RELEASE_TAG" == *"/"* ]]; then
19+
FORMATTED_TAG="/${RELEASE_TAG%/*}@${RELEASE_TAG##*/}"
20+
else
21+
FORMATTED_TAG="@${RELEASE_TAG}"
22+
fi
23+
24+
# Construct the full URL
25+
FULL_URL="${BASE_URL}/${REPO_URL}${FORMATTED_TAG}"
26+
echo "Sending POST request to $FULL_URL"
27+
28+
# Send the POST request
29+
curl -X POST "$FULL_URL" --fail || echo "Failed to notify pkg.go.dev"
30+
31+
commit:
32+
needs: refresh
33+
strategy:
34+
matrix:
35+
os: [ubuntu-22.04]
36+
go: ['1.22']
37+
runs-on: ubuntu-latest
38+
permissions:
39+
contents: write
40+
steps:
41+
- uses: actions/checkout@v4
42+
with:
43+
ref: ${{ github.head_ref }}
44+
45+
- uses: actions/setup-go@v5
46+
with:
47+
go-version: ${{ matrix.go }}
48+
49+
- uses: actions/cache@v4
50+
with:
51+
path: |
52+
~/.cache/go-build
53+
~/go/pkg/mod
54+
key: ${{ runner.os }}-${{ matrix.go }}-${{ hashFiles('**/go.sum') }}
55+
restore-keys: ${{ runner.os }}-${{ matrix.go }}-${{ hashFiles('**/go.sum') }}
56+
57+
- name: Update Dependency
58+
run: make update
59+
60+
- name: Update go.work
61+
run: |
62+
REPO_URL="github.com/${{ github.repository }}"
63+
RELEASE_TAG="${{ github.event.release.tag_name }}"
64+
65+
# If the tag contains '/', replace the last '/' with '@'
66+
if [[ "$RELEASE_TAG" == *"/"* ]]; then
67+
PACKAGE_URL="${REPO_URL}/${RELEASE_TAG%/*}"
68+
PACKAGE_VERSION="${RELEASE_TAG##*/}"
69+
else
70+
PACKAGE_URL="${REPO_URL}"
71+
PACKAGE_VERSION="${RELEASE_TAG}"
72+
fi
73+
74+
GO_WORK_FILE=".go.work"
75+
76+
# Update the go.work file using sed to replace the version
77+
sed -i -E \
78+
-e "s|${PACKAGE_URL} v[0-9]+\.[0-9]+\.[0-9]+|${PACKAGE_URL} ${PACKAGE_VERSION}|" \
79+
"$GO_WORK_FILE"
80+
81+
- uses: stefanzweifel/git-auto-commit-action@v5
82+
with:
83+
commit_message: "chore(deploy): deploy ${{ github.event.release.tag_name }} version"
84+
branch: main

0 commit comments

Comments
 (0)