CD #7
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CD | |
on: | |
release: | |
types: [published] | |
jobs: | |
refresh: | |
runs-on: ubuntu-latest | |
steps: | |
- 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" |