-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4674bf
commit cd3d3bc
Showing
1 changed file
with
66 additions
and
82 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,51 @@ jobs: | |
build_and_release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# ... (previous steps remain the same) | ||
- name: Checkout the repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 'stable' | ||
|
||
- name: Install dependencies | ||
run: go mod download | ||
|
||
- name: Build binaries | ||
run: | | ||
mkdir -p ${{ env.BUILD_DIR }} | ||
PLATFORMS=( | ||
"darwin/arm64" | ||
"darwin/amd64" | ||
"linux/arm64" | ||
"linux/amd64" | ||
"windows/amd64" | ||
"windows/arm64" | ||
"freebsd/386" | ||
"freebsd/amd64" | ||
"freebsd/arm" | ||
"freebsd/arm64" | ||
"openbsd/386" | ||
"openbsd/amd64" | ||
"openbsd/arm" | ||
"openbsd/arm64" | ||
"dragonfly/amd64" | ||
"netbsd/386" | ||
"netbsd/amd64" | ||
"netbsd/arm" | ||
"netbsd/arm64" | ||
) | ||
for PLATFORM in "${PLATFORMS[@]}"; do | ||
GOOS=${PLATFORM%/*} | ||
GOARCH=${PLATFORM#*/} | ||
OUTPUT_NAME=${{ env.BINARY_PREFIX }}.$GOOS.$GOARCH | ||
if [ "$GOOS" = "windows" ]; then | ||
OUTPUT_NAME=$OUTPUT_NAME.exe | ||
fi | ||
echo "Building for $GOOS/$GOARCH..." | ||
GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-X 'main.Version=$(date +'%Y-%m-%d_%H:%M:%S')'" -o "${{ env.BUILD_DIR }}/$OUTPUT_NAME" ${{ env.SOURCE_DIR }} | ||
done | ||
- name: Delete existing release | ||
uses: dev-drprasad/[email protected] | ||
|
@@ -34,55 +78,17 @@ jobs: | |
|
||
- name: Create Release | ||
id: create_release | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const maxRetries = 3; | ||
let release; | ||
for (let i = 0; i < maxRetries; i++) { | ||
try { | ||
console.log(`Attempting to create release (attempt ${i + 1})...`); | ||
release = await github.rest.repos.createRelease({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
tag_name: '${{ env.TAG }}', | ||
name: '${{ env.RELEASE_NAME }}', | ||
body: '${{ github.event.inputs.releaseNote || 'Automated release' }}', | ||
draft: false, | ||
prerelease: false | ||
}); | ||
console.log(`Release created successfully: ${release.data.html_url}`); | ||
break; | ||
} catch (error) { | ||
console.error(`Attempt ${i + 1} failed: ${error.message}`); | ||
if (i === maxRetries - 1) throw error; | ||
await new Promise(r => setTimeout(r, 5000)); // Wait 5 seconds before retrying | ||
} | ||
} | ||
if (!release) { | ||
throw new Error('Failed to create release after multiple attempts'); | ||
} | ||
return release.data.upload_url; | ||
- name: Verify Release | ||
if: success() | ||
uses: actions/github-script@v6 | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const release = await github.rest.repos.getRelease({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
release_id: '${{ env.TAG }}' | ||
}); | ||
console.log(`Release verification - ID: ${release.data.id}, Name: ${release.data.name}, Tag: ${release.data.tag_name}`); | ||
if (!release.data.id) { | ||
throw new Error('Release was not created properly'); | ||
} | ||
tag_name: ${{ env.TAG }} | ||
release_name: ${{ env.RELEASE_NAME }} | ||
body: ${{ github.event.inputs.releaseNote || 'Automated release' }} | ||
draft: false | ||
prerelease: false | ||
|
||
- name: Upload Release Assets | ||
if: success() | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
uses: actions/github-script@v6 | ||
|
@@ -92,42 +98,20 @@ jobs: | |
const fs = require('fs').promises; | ||
const path = require('path'); | ||
const uploadUrl = '${{ steps.create_release.outputs.result }}'; | ||
const uploadUrl = '${{ steps.create_release.outputs.upload_url }}'; | ||
const buildDir = '${{ env.BUILD_DIR }}'; | ||
try { | ||
const files = await fs.readdir(buildDir); | ||
console.log(`Found ${files.length} files in ${buildDir}`); | ||
for (const file of files) { | ||
const filePath = path.join(buildDir, file); | ||
const stat = await fs.stat(filePath); | ||
if (stat.isFile()) { | ||
console.log(`Uploading ${file}...`); | ||
const fileContent = await fs.readFile(filePath); | ||
try { | ||
const response = await github.rest.repos.uploadReleaseAsset({ | ||
url: uploadUrl, | ||
headers: { | ||
'content-type': 'application/octet-stream', | ||
'content-length': fileContent.length, | ||
}, | ||
name: file, | ||
data: fileContent, | ||
}); | ||
console.log(`Successfully uploaded ${file}`); | ||
} catch (error) { | ||
console.error(`Failed to upload ${file}: ${error.message}`); | ||
} | ||
} | ||
const files = await fs.readdir(buildDir); | ||
for (const file of files) { | ||
const filePath = path.join(buildDir, file); | ||
const stat = await fs.stat(filePath); | ||
if (stat.isFile()) { | ||
console.log(`Uploading ${file}...`); | ||
await github.rest.repos.uploadReleaseAsset({ | ||
url: uploadUrl, | ||
headers: { 'content-type': 'application/octet-stream' }, | ||
name: file, | ||
data: await fs.readFile(filePath) | ||
}); | ||
} | ||
} catch (error) { | ||
console.error(`Error accessing ${buildDir}: ${error.message}`); | ||
throw error; | ||
} | ||
- name: Check release status | ||
if: failure() | ||
run: | | ||
echo "Release creation or asset upload failed. Check the logs for more information." | ||
exit 1 |