diff --git a/.gitea/workflows/releases.yml b/.gitea/workflows/releases.yml index a269179..32369e3 100644 --- a/.gitea/workflows/releases.yml +++ b/.gitea/workflows/releases.yml @@ -13,15 +13,20 @@ jobs: steps: # ------------------------------------------------------------ - # Checkout + # Checkout (Native Git - No Node.js required) # ------------------------------------------------------------ - name: Checkout - uses: actions/checkout@v4 - - - name: Configure Git Safe Directory shell: bash + env: + GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - git config --global --add safe.directory "$GITHUB_WORKSPACE" || true + git config --global --add safe.directory "$GITHUB_WORKSPACE" + SERVER_HOST=$(echo "${{ github.server_url }}" | sed -e 's|^https://||' -e 's|^http://||') + git init + git remote add origin "https://${GITEA_TOKEN}@${SERVER_HOST}/${{ github.repository }}.git" || \ + git remote set-url origin "https://${GITEA_TOKEN}@${SERVER_HOST}/${{ github.repository }}.git" + git fetch --depth 1 origin "${{ github.sha }}" || git fetch --depth 1 origin main + git checkout -f FETCH_HEAD # ------------------------------------------------------------ # Build firmware & merged binary @@ -35,9 +40,6 @@ jobs: idf.py build idf.py merge-bin - # ------------------------------------------------------------ - # Prepare release artifacts - # ------------------------------------------------------------ # ------------------------------------------------------------ # Prepare release artifacts & calculate hashes # ------------------------------------------------------------ @@ -81,7 +83,7 @@ jobs: ls -lh release/ # ------------------------------------------------------------ - # Delete existing "latest" release + # Delete existing "latest" release & tag # ------------------------------------------------------------ - name: Delete existing latest release shell: bash @@ -106,37 +108,61 @@ jobs: || true # ------------------------------------------------------------ - # Create latest release + # Create latest release and upload assets (Native API & Curl) # ------------------------------------------------------------ - name: Create latest release - uses: akkuman/gitea-release-action@v1 - with: - server_url: ${{ github.server_url }} - repository: ${{ github.repository }} - token: ${{ secrets.GITHUB_TOKEN }} + shell: bash + env: + GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + API="${{ github.server_url }}/api/v1/repos/${{ github.repository }}" - tag_name: latest - name: "Latest ESP32 Firmware" + export RELEASE_BODY="Automatically built from the \`main\` branch. - body: | - Automatically built from the `main` branch. + Commit: + ${{ github.sha }} - Commit: - ${{ github.sha }} + SHA256: + ${{ env.IMG_SHA256 }} - SHA256: - ${{ env.IMG_SHA256 }} + File-SHA256: + ${{ env.BIN_SHA256 }} - File-SHA256: - ${{ env.BIN_SHA256 }} + ESP-IDF: + 5.5 - ESP-IDF: - 5.5 + Target: + ESP32 - Target: - ESP32 + This release is automatically replaced on every push to \`main\`." - This release is automatically replaced on every push to `main`. + REL_ID=$(python3 -c "import urllib.request, json, os + api = '${API}' + token = os.environ['GITEA_TOKEN'] + headers = {'Authorization': f'token {token}', 'Content-Type': 'application/json'} + payload = { + 'tag_name': 'latest', + 'target_commitish': 'main', + 'name': 'Latest ESP32 Firmware', + 'body': os.environ.get('RELEASE_BODY', ''), + 'draft': False, + 'prerelease': False + } + req = urllib.request.Request(f'{api}/releases', data=json.dumps(payload).encode('utf-8'), headers=headers, method='POST') + with urllib.request.urlopen(req) as resp: + print(json.loads(resp.read().decode('utf-8'))['id']) + ") - files: | - release/* + echo "Created release ID: ${REL_ID}" + + for fpath in release/*; do + [ -f "$fpath" ] || continue + echo "Uploading $fpath..." + curl -fsSL \ + -X POST \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -F "attachment=@${fpath}" \ + "${API}/releases/${REL_ID}/assets" + done + + echo "Release created and all assets uploaded successfully!"