Skip to content

Commit

Permalink
docs: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pwltr committed Jun 21, 2022
1 parent 33e1236 commit c3a97c5
Show file tree
Hide file tree
Showing 12 changed files with 1,256 additions and 299 deletions.
26 changes: 23 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: recursive

- name: Setup Node
uses: actions/setup-node@v2.5.1
uses: actions/setup-node@v3
with:
node-version: 16.14.0
node-version: 16

- name: Setup Rust
uses: actions-rs/[email protected]
Expand Down Expand Up @@ -66,4 +66,24 @@ jobs:
tagName: ${{ github.ref_name }}
releaseName: ${{ github.ref_name }}
releaseDraft: true
releaseBody: 'See the assets to download this version and install.'
prerelease: false
update:
needs: release
runs-on: macos-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16

- name: Install dependencies
run: yarn

- name: Create Update
run: yarn update
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: recursive

- name: Setup Node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 16

- name: Install dependencies
run: yarn
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"build": "tsc && vite build",
"preview": "vite preview",
"tauri": "tauri",
"update": "node scripts/update.mjs",
"tsc:check": "tsc -p tsconfig.json --noEmit",
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
"format:check": "prettier --check \"src/**/*.{ts,tsx}\"",
Expand Down Expand Up @@ -35,6 +36,7 @@
"uuid": "^8.3.2"
},
"devDependencies": {
"@actions/github": "^5.0.1",
"@commitlint/cli": "^17.0.2",
"@commitlint/config-conventional": "^17.0.2",
"@ptsecurity/commitlint-config": "^2.0.0",
Expand Down
72 changes: 72 additions & 0 deletions scripts/update.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import fetch from 'node-fetch'
import { getOctokit, context } from '@actions/github'

const UPDATE_TAG_NAME = 'updater'
const UPDATE_FILE_NAME = 'update.json'

const getSignature = async (url) => {
const response = await fetch(url, {
method: 'GET',
headers: { 'Content-Type': 'application/octet-stream' },
})
return response.text()
}

const updateData = {
name: '',
pub_date: new Date().toISOString(),
platforms: {
win64: { signature: '', url: '' },
linux: { signature: '', url: '' },
darwin: { signature: '', url: '' },
'linux-x86_64': { signature: '', url: '' },
'windows-x86_64': { signature: '', url: '' },
},
}

const octokit = getOctokit(process.env.GITHUB_TOKEN)
const options = { owner: context.repo.owner, repo: context.repo.repo }

const { data: release } = await octokit.rest.repos.getLatestRelease(options)
updateData.name = release.tag_name
for (const { name, browser_download_url } of release.assets) {
if (name.endsWith('.msi.zip')) {
updateData.platforms.win64.url = browser_download_url
updateData.platforms['windows-x86_64'].url = browser_download_url
} else if (name.endsWith('.msi.zip.sig')) {
const signature = await getSignature(browser_download_url)
updateData.platforms.win64.signature = signature
updateData.platforms['windows-x86_64'].signature = signature
} else if (name.endsWith('.app.tar.gz')) {
updateData.platforms.darwin.url = browser_download_url
} else if (name.endsWith('.app.tar.gz.sig')) {
const signature = await getSignature(browser_download_url)
updateData.platforms.darwin.signature = signature
} else if (name.endsWith('.AppImage.tar.gz')) {
updateData.platforms.linux.url = browser_download_url
updateData.platforms['linux-x86_64'].url = browser_download_url
} else if (name.endsWith('.AppImage.tar.gz.sig')) {
const signature = await getSignature(browser_download_url)
updateData.platforms.linux.signature = signature
updateData.platforms['linux-x86_64'].signature = signature
}
}

const { data: updater } = await octokit.rest.repos.getReleaseByTag({
...options,
tag: UPDATE_TAG_NAME,
})

for (const { id, name } of updater.assets) {
if (name === UPDATE_FILE_NAME) {
await octokit.rest.repos.deleteReleaseAsset({ ...options, asset_id: id })
break
}
}

await octokit.rest.repos.uploadReleaseAsset({
...options,
release_id: updater.id,
name: UPDATE_FILE_NAME,
data: JSON.stringify(updateData),
})
Loading

0 comments on commit c3a97c5

Please sign in to comment.