From 404afe4786488a2b7410d8bb2b59a3d9a1814fe7 Mon Sep 17 00:00:00 2001 From: Salastil Date: Sun, 16 Nov 2025 16:20:34 -0500 Subject: [PATCH] Add Gitea Actions CI/CD workflow for automated builds and releases --- .gitea/workflows/build.yml | 159 +++++++++++++++++++++++++++++++++++++ .gitignore | 1 - README.md | 2 +- go.sum | 19 +++++ 4 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 .gitea/workflows/build.yml create mode 100644 go.sum diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..d02b9b5 --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,159 @@ +name: Build & Release +on: + push: + branches: ["master"] + tags: + - 'v*.*' + +jobs: + build-latest: + runs-on: ubuntu-latest + if: github.ref_type == 'branch' + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: "1.22" + + - name: Build Binary + run: | + go mod tidy + go build -o Sneedchat-Discord-Bridge . + + - name: Delete Previous Latest Release + continue-on-error: true + env: + GITEA_TOKEN: ${{ secrets.CI_TOKEN }} + run: | + curl -X DELETE \ + -H "Authorization: token ${GITEA_TOKEN}" \ + "https://git.salastil.com/api/v1/repos/Salastil/Sneedchat-Discord-Bridge-Go/releases/tags/latest" + + - name: Delete Latest Tag + continue-on-error: true + run: | + git push origin :refs/tags/latest || true + + - name: Create Latest Tag + run: | + git config user.name "Gitea Actions" + git config user.email "actions@gitea.local" + git tag latest + git push origin latest + + - name: Create Latest Release and Upload Binary + env: + GITEA_TOKEN: ${{ secrets.CI_TOKEN }} + run: | + set -x + + # Verify token exists + if [ -z "$GITEA_TOKEN" ]; then + echo "ERROR: CI_TOKEN secret is not set!" + exit 1 + fi + + # Create release + RESPONSE=$(curl -X POST \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/json" \ + -d '{ + "tag_name": "latest", + "name": "Latest Build (Development)", + "body": "Automated build from master branch commit ${{ github.sha }}", + "draft": false, + "prerelease": true + }' \ + "https://git.salastil.com/api/v1/repos/Salastil/Sneedchat-Discord-Bridge-Go/releases") + + echo "Create release response: $RESPONSE" + + # Extract release ID + RELEASE_ID=$(echo "$RESPONSE" | grep -o '"id":[0-9]*' | head -1 | grep -o '[0-9]*') + + echo "Release ID: $RELEASE_ID" + + if [ -z "$RELEASE_ID" ]; then + echo "Failed to create release or extract release ID" + exit 1 + fi + + # Upload binary + curl -X POST \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/octet-stream" \ + --data-binary @Sneedchat-Discord-Bridge \ + "https://git.salastil.com/api/v1/repos/Salastil/Sneedchat-Discord-Bridge-Go/releases/$RELEASE_ID/assets?name=Sneedchat-Discord-Bridge" + + version-release: + runs-on: ubuntu-latest + if: github.ref_type == 'tag' && startsWith(github.ref_name, 'v') + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: "1.22" + + - name: Build Multi-Platform Binaries + run: | + mkdir -p dist + go mod tidy + GOOS=linux GOARCH=amd64 go build -o dist/Sneedchat-Discord-Bridge-linux-amd64 . + GOOS=linux GOARCH=arm64 go build -o dist/Sneedchat-Discord-Bridge-linux-arm64 . + GOOS=windows GOARCH=amd64 go build -o dist/Sneedchat-Discord-Bridge-windows-amd64.exe . + GOOS=darwin GOARCH=amd64 go build -o dist/Sneedchat-Discord-Bridge-darwin-amd64 . + GOOS=darwin GOARCH=arm64 go build -o dist/Sneedchat-Discord-Bridge-darwin-arm64 . + + - name: Create Version Release and Upload Binaries + env: + GITEA_TOKEN: ${{ secrets.CI_TOKEN }} + run: | + set -x + + # Verify token exists + if [ -z "$GITEA_TOKEN" ]; then + echo "ERROR: CI_TOKEN secret is not set!" + exit 1 + fi + + # Create release + RESPONSE=$(curl -X POST \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/json" \ + -d '{ + "tag_name": "${{ github.ref_name }}", + "name": "Release ${{ github.ref_name }}", + "body": "Release ${{ github.ref_name }}", + "draft": false, + "prerelease": false + }' \ + "https://git.salastil.com/api/v1/repos/Salastil/Sneedchat-Discord-Bridge-Go/releases") + + echo "Create release response: $RESPONSE" + + # Extract release ID + RELEASE_ID=$(echo "$RESPONSE" | grep -o '"id":[0-9]*' | head -1 | grep -o '[0-9]*') + + echo "Release ID: $RELEASE_ID" + + if [ -z "$RELEASE_ID" ]; then + echo "Failed to create release or extract release ID" + exit 1 + fi + + # Upload all binaries + for file in dist/*; do + filename=$(basename "$file") + echo "Uploading $filename..." + curl -X POST \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/octet-stream" \ + --data-binary @"$file" \ + "https://git.salastil.com/api/v1/repos/Salastil/Sneedchat-Discord-Bridge-Go/releases/$RELEASE_ID/assets?name=$filename" + done \ No newline at end of file diff --git a/.gitignore b/.gitignore index 419d0fa..1b433ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -go.sum Sneedchat-Discord-Bridge file.log diff --git a/README.md b/README.md index fae7160..17ff161 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ A high-performance bridge written in Go that synchronizes messages between Kiwi **Typical resource usage:** - **CPU**: Efficient, easily handled by a Raspberry Pi, a few % on cpu usage at heavy load. -- **Memory**: 50-70 MB at full load in a busy channel +- **Memory**: 10-15 MB at full load in a busy channel - **Network**: Minimal (< 1 MB/minute) except when uploading attachments ## Requirements diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..c93edbf --- /dev/null +++ b/go.sum @@ -0,0 +1,19 @@ +github.com/bwmarrin/discordgo v0.27.1 h1:ib9AIc/dom1E/fSIulrBwnez0CToJE113ZGt4HoliGY= +github.com/bwmarrin/discordgo v0.27.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY= +github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= +github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=