implement hedgedoc && docusaurus #41
Workflow file for this run
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
name: Build and Package Demo Server | |
on: | |
workflow_dispatch: # for manual testing | |
release: | |
types: [created, released] | |
push: | |
tags: | |
- 'v0.0.1' | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
jobs: | |
build-arm64: | |
name: Build ARM64 Server | |
runs-on: ubuntu-latest | |
container: | |
image: ionutnqm/arm64-libs:latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Debug Current Path and List Files | |
run: | | |
echo "Current directory:" | |
pwd | |
echo "List of files:" | |
ls -l | |
- name: Build ARM64 Server | |
run: aarch64-linux-gnu-gcc -o server_arm64 debian-brski/brski-demo-app-deb/opt/demo-server/server.c -L/libmicrohttpd/src/microhttpd/.libs -L/zlib -lmicrohttpd -lz -static | |
- name: Upload server binary as an artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: server-arm64-binary | |
path: server_arm64 | |
build-x86_64: | |
name: Build x86_64 Server | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Update package lists | |
run: sudo apt-get update | |
- name: Install libmicrohttpd | |
run: sudo apt-get install -y libmicrohttpd-dev | |
- name: Create Directory for x86_64 Binary | |
run: mkdir -p brski-demo-app-deb/opt/demo-server/ | |
- name: Build x86_64 Server | |
run: gcc -o server_x86_64 debian-brski/brski-demo-app-deb/opt/demo-server/server.c -lmicrohttpd | |
- name: List files after build | |
run: | | |
echo "Current directory for x86_64:" | |
pwd | |
echo "List of files:" | |
ls -l | |
- name: Rename x86_64 binary for packaging | |
run: mv server_x86_64 brski-demo-app-deb/opt/demo-server/server_x86_64 | |
- name: Upload x86_64 server binary as an artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: server-x86_64-binary | |
path: brski-demo-app-deb/opt/demo-server/server_x86_64 | |
package-deb: | |
name: Package Debian | |
runs-on: ubuntu-latest | |
needs: [build-arm64, build-x86_64] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Download ARM64 server binary | |
uses: actions/download-artifact@v2 | |
with: | |
name: server-arm64-binary | |
path: debian-brski/brski-demo-app-deb/opt/demo-server/ | |
- name: Set execute permission on ARM64 Server Binary | |
run: sudo chmod +x debian-brski/brski-demo-app-deb/opt/demo-server/server_arm64 | |
- name: Build ARM64 Debian Package | |
run: dpkg-deb --build debian-brski/brski-demo-app-deb brski-demo-app-deb_arm64.deb | |
- name: Remove ARM64 binary | |
run: rm debian-brski/brski-demo-app-deb/opt/demo-server/server_arm64 | |
- name: Download x86_64 server binary | |
uses: actions/download-artifact@v2 | |
with: | |
name: server-x86_64-binary | |
path: debian-brski/brski-demo-app-deb/opt/demo-server/ | |
- name: Set execute permission on x86_64 Server Binary | |
run: sudo chmod +x debian-brski/brski-demo-app-deb/opt/demo-server/server_x86_64 | |
- name: Build x86_64 Debian Package | |
run: dpkg-deb --build debian-brski/brski-demo-app-deb brski-demo-app-deb-x86_64.deb | |
- name: Upload ARM64 .deb Package to Artifacts | |
uses: actions/upload-artifact@v2 | |
with: | |
name: brski-demo-app-deb-arm64 | |
path: brski-demo-app-deb_arm64.deb | |
- name: Upload x86_64 .deb Package to Artifacts | |
uses: actions/upload-artifact@v2 | |
with: | |
name: brski-demo-app-deb-x86_64 | |
path: brski-demo-app-deb-x86_64.deb | |
# changed to only update the assets of current release instead of creating a new release | |
release-debs: | |
name: Update Release Assets for Debian Packages | |
runs-on: ubuntu-latest | |
needs: [build-arm64, build-x86_64, package-deb] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up release information | |
run: | | |
echo "RELEASE_TAG=v0.0.1" >> $GITHUB_ENV | |
echo "RELEASE_NAME=Brski-demo-app v0.0.1" >> $GITHUB_ENV | |
- name: Check if Release Exists | |
id: check_release | |
run: | | |
RELEASE_DATA=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
"https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ env.RELEASE_TAG }}") | |
RELEASE_ID=$(echo "$RELEASE_DATA" | jq -r '.id') | |
UPLOAD_URL=$(echo "$RELEASE_DATA" | jq -r '.upload_url') | |
if [[ "$RELEASE_ID" != "null" ]]; then | |
echo "UPLOAD_URL=${UPLOAD_URL}" >> $GITHUB_ENV | |
echo "exists=true" >> $GITHUB_ENV | |
echo "RELEASE_ID=$RELEASE_ID" >> $GITHUB_ENV | |
else | |
echo "exists=false" >> $GITHUB_ENV | |
fi | |
echo "RELEASE_ID: $RELEASE_ID" | |
echo "UPLOAD_URL (masked): ${UPLOAD_URL/\{?name,label\}/}" | |
- name: Download ARM64 Debian Package | |
if: env.exists == 'true' | |
uses: actions/download-artifact@v2 | |
with: | |
name: brski-demo-app-deb-arm64 | |
path: . | |
- name: Download AMD64 Debian Package | |
if: env.exists == 'true' | |
uses: actions/download-artifact@v2 | |
with: | |
name: brski-demo-app-deb-x86_64 | |
path: . | |
- name: List files in current directory | |
run: ls -lah | |
- name: Upload ARM64 Debian Package to Release | |
if: env.exists == 'true' | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const fs = require('fs'); | |
const path = './brski-demo-app-deb_arm64.deb'; | |
const asset_name = 'brski-demo-app-deb_arm64.deb'; | |
try { | |
// Check if the file exists | |
if (!fs.existsSync(path)) { | |
console.error(`File not found: ${path}`); | |
} | |
const { owner, repo } = context.repo; | |
const release_id = process.env.RELEASE_ID; | |
console.log(`release_id: ${process.env.RELEASE_ID}`); | |
// Delete existing asset with the same name | |
const assets = await github.rest.repos.listReleaseAssets({ owner, repo, release_id }); | |
const existingAsset = assets.data.find(asset => asset.name === asset_name); | |
console.log(`Existing assets: ${existingAsset}`); | |
console.log(`UPLOAD URL: ${process.env.UPLOAD_URL}`); | |
if (existingAsset) { | |
await github.rest.repos.deleteReleaseAsset({ | |
owner, | |
repo, | |
asset_id: existingAsset.id | |
}); | |
} | |
// Upload the new asset | |
const contentLength = fs.statSync(path).size; | |
const headers = { 'content-type': 'application/vnd.debian.binary-package', 'content-length': contentLength }; | |
const upload_url = process.env.UPLOAD_URL; | |
const asset = fs.readFileSync(path); | |
await github.rest.repos.uploadReleaseAsset({ | |
url: upload_url, | |
headers, | |
name: asset_name, | |
data: asset | |
}); | |
} catch (error) { | |
console.error(`Error uploading ${asset_name}, ${error}`); | |
} | |
- name: Upload AMD64 Debian Package to Release | |
if: env.exists == 'true' | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const fs = require('fs'); | |
const path = './brski-demo-app-deb-x86_64.deb'; | |
const asset_name = 'brski-demo-app-deb-x86_64.deb'; | |
try { | |
// Check if the file exists | |
if (!fs.existsSync(path)) { | |
console.error(`File not found: ${path}`); | |
} | |
const { owner, repo } = context.repo; | |
const release_id = process.env.RELEASE_ID; | |
// Delete existing asset with the same name | |
const assets = await github.rest.repos.listReleaseAssets({ owner, repo, release_id }); | |
const existingAsset = assets.data.find(asset => asset.name === asset_name); | |
if (existingAsset) { | |
await github.rest.repos.deleteReleaseAsset({ | |
owner, | |
repo, | |
asset_id: existingAsset.id | |
}); | |
} | |
// Upload the new asset | |
const contentLength = fs.statSync(path).size; | |
const headers = { 'content-type': 'application/vnd.debian.binary-package', 'content-length': contentLength }; | |
const upload_url = process.env.UPLOAD_URL; | |
const asset = fs.readFileSync(path); | |
await github.rest.repos.uploadReleaseAsset({ | |
url: upload_url, | |
headers, | |
name: asset_name, | |
data: asset | |
}); | |
} catch (error) { | |
console.error(`Error uploading ${asset_name}, ${error}`); | |
} |