name: Build Firefox Extension on: push: branches: - main tags: - 'v*' pull_request: branches: - main jobs: build: runs-on: docker permissions: contents: read packages: write container: image: node:20-alpine steps: - name: Install dependencies run: apk add --no-cache zip jq git curl - name: Checkout repository uses: actions/checkout@v3 - name: Get version from manifest id: version run: | VERSION=$(jq -r '.version' manifest.json) echo "version=$VERSION" >> $GITHUB_OUTPUT echo "Building version: $VERSION" - name: Create extension package run: | # Create build directory mkdir -p build # Package the extension as XPI (which is just a ZIP file) zip -r build/firefox-containerbookmarks-${{ steps.version.outputs.version }}.xpi \ manifest.json \ background.js \ icons/ \ popup/ \ README.md \ -x "*.git*" \ -x "*.md" \ -x "build/*" \ -x "node_modules/*" \ -x ".gitea/*" # Also create a ZIP for convenience cp build/firefox-containerbookmarks-${{ steps.version.outputs.version }}.xpi \ build/firefox-containerbookmarks-${{ steps.version.outputs.version }}.zip - name: Upload to Gitea Packages run: | VERSION="${{ steps.version.outputs.version }}" PACKAGE_URL="${GITHUB_SERVER_URL}/api/packages/${GITHUB_REPOSITORY_OWNER}/generic/firefox-containerbookmarks/${VERSION}/firefox-containerbookmarks-${VERSION}.xpi" # Try to upload, if 409 (already exists) try to delete and re-upload HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \ -H "Authorization: token ${{ secrets.ACCESS_TOKEN }}" \ --upload-file "build/firefox-containerbookmarks-${VERSION}.xpi" \ "${PACKAGE_URL}") if [ "$HTTP_CODE" = "409" ]; then echo "Package already exists, deleting and re-uploading..." curl -X DELETE -H "Authorization: token ${{ secrets.ACCESS_TOKEN }}" "${PACKAGE_URL}" curl --fail \ -H "Authorization: token ${{ secrets.ACCESS_TOKEN }}" \ --upload-file "build/firefox-containerbookmarks-${VERSION}.xpi" \ "${PACKAGE_URL}" elif [ "$HTTP_CODE" != "201" ] && [ "$HTTP_CODE" != "200" ]; then echo "Upload failed with HTTP code: $HTTP_CODE" exit 1 fi echo "✅ Package uploaded successfully: ${PACKAGE_URL}" release: runs-on: docker container: image: node:20-alpine needs: build if: startsWith(github.ref, 'refs/tags/v') steps: - name: Install dependencies run: apk add --no-cache jq git curl - name: Checkout repository uses: actions/checkout@v3 - name: Get version from manifest id: version run: | VERSION=$(jq -r '.version' manifest.json) echo "version=$VERSION" >> $GITHUB_OUTPUT - name: Download from Gitea Packages run: | mkdir -p build curl --fail -o "build/firefox-containerbookmarks-${{ steps.version.outputs.version }}.xpi" \ "${GITHUB_SERVER_URL}/api/packages/${GITHUB_REPOSITORY_OWNER}/generic/firefox-containerbookmarks/${{ steps.version.outputs.version }}/firefox-containerbookmarks-${{ steps.version.outputs.version }}.xpi" - name: Create Release uses: softprops/action-gh-release@v1 with: files: build/*.xpi generate_release_notes: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}