From 708f4292c0a60461faeda9f85c875ee3b0507f65 Mon Sep 17 00:00:00 2001 From: siyul-park Date: Mon, 20 Jan 2025 13:16:36 +0900 Subject: [PATCH] chore(actions): add auto commit in cd --- .github/workflows/cd.yml | 75 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 5721bede..90e43a06 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -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