Skip to content

Commit

Permalink
chore(actions): add auto commit in cd
Browse files Browse the repository at this point in the history
  • Loading branch information
siyul-park committed Jan 20, 2025
1 parent b77c4eb commit 708f429
Showing 1 changed file with 73 additions and 2 deletions.
75 changes: 73 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,81 @@ name: CD

on:
release:
types: [ published ]
types: [published]

jobs:
refresh:
runs-on: ubuntu-latest
steps:
- uses: siyul-park/notify-pkg-go-dev@v1
- run: |
# Parameters from the Action inputs
BASE_URL="https://pkg.go.dev/fetch"
REPO_URL="github.com/${{ github.repository }}"
RELEASE_TAG="${{ github.event.release.tag_name }}"
# If the tag contains '/', replace the last '/' with '@'
if [[ "$RELEASE_TAG" == *"/"* ]]; then
FORMATTED_TAG="/${RELEASE_TAG%/*}@${RELEASE_TAG##*/}"
else
FORMATTED_TAG="@${RELEASE_TAG}"
fi
# Construct the full URL
FULL_URL="${BASE_URL}/${REPO_URL}${FORMATTED_TAG}"
echo "Sending POST request to $FULL_URL"
# Send the POST request
curl -X POST "$FULL_URL" --fail || echo "Failed to notify pkg.go.dev"
commit:
needs: refresh
strategy:
matrix:
os: [ubuntu-22.04]
go: ['1.22']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}

- uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-${{ matrix.go }}-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-${{ matrix.go }}-${{ hashFiles('**/go.sum') }}

- name: Update Dependency
run: make update

- name: Update go.work
run: |
REPO_URL="github.com/${{ github.repository }}"
RELEASE_TAG="${{ github.event.release.tag_name }}"
# If the tag contains '/', replace the last '/' with '@'
if [[ "$RELEASE_TAG" == *"/"* ]]; then
PACKAGE_URL="${REPO_URL}/${RELEASE_TAG%/*}"
PACKAGE_VERSION="${RELEASE_TAG##*/}"
else
PACKAGE_URL="${REPO_URL}"
PACKAGE_VERSION="${RELEASE_TAG}"
fi
GO_WORK_FILE=".go.work"
# Update the go.work file using sed to replace the version
sed -i -E \
-e "s|${PACKAGE_URL} v[0-9]+\.[0-9]+\.[0-9]+|${PACKAGE_URL} ${PACKAGE_VERSION}|" \
"$GO_WORK_FILE"
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "chore(deploy): deploy ${{ github.event.release.tag_name }} version"
branch: main

0 comments on commit 708f429

Please sign in to comment.