Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI/CD] Fix linux and mac builds and releases. Automate flathub releases #411

Merged
merged 22 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions .github/workflows/build.yml
flavioislima marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
submodules: 'recursive'
token: ${{ secrets.pat }}
- name: Setup NodeJS
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Reconfigure git to use HTTP authentication
Expand All @@ -37,9 +37,9 @@ jobs:
- name: Install modules.
run: npm i --legacy-peer-deps
- name: Build artifacts.
run: npm run dist:win nsis
run: npm run dist:win
- name: Upload EXE.
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: win-setup
path: dist/HyperPlay*.exe
Expand All @@ -50,13 +50,15 @@ jobs:
group: build-linux-${{ github.ref }}
cancel-in-progress: true
steps:
- name: Install libarchive-tools for pacman build # Related https://github.com/electron-userland/electron-builder/issues/4181
run: sudo apt-get install libarchive-tools
- name: Checkout repository.
uses: actions/checkout@v3
with:
submodules: 'recursive'
token: ${{ secrets.pat }}
- name: Setup NodeJS
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Reconfigure git to use HTTP authentication
Expand All @@ -67,14 +69,12 @@ jobs:
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
- name: Install modules.
run: yarn
- name: Build artifacts.
run: yarn dist:linux tar.xz --publish=never
- name: Upload Tar.xz.
uses: actions/upload-artifact@v2
with:
name: linux-appimage
path: dist/hyperplay*.tar.xz
retention-days: 14
- name: Build deb artifact
run: yarn dist:linux:ci:deb
- name: Build rpm artifact
run: yarn dist:linux:ci:rpm
BrettCleary marked this conversation as resolved.
Show resolved Hide resolved
- name: Build pacman artifact
run: yarn dist:linux:ci:pacman
build_mac:
runs-on: macos-13
concurrency:
Expand All @@ -87,7 +87,7 @@ jobs:
submodules: 'recursive'
token: ${{ secrets.pat }}
- name: Setup NodeJS
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Reconfigure git to use HTTP authentication
Expand All @@ -99,7 +99,7 @@ jobs:
- name: Install modules.
run: yarn
- name: Build artifacts.
run: yarn dist:mac --x64 --arm64 --publish=never
run: yarn dist:mac
env:
NOTARIZE: false
- name: Upload Intel build.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codecheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
submodules: 'recursive'
token: ${{ secrets.pat }}
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
node-version: '16'
- name: Reconfigure git to use HTTP authentication
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/flatpak-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Install modules.
run: npm i --legacy-peer-deps
- name: Build artifacts.
run: npm run dist:linux tar.xz --publish=never
run: npm run dist:linux:ci:flatpak
- name: Prepare Flatpak
run: npm run flatpak:prepare
- name: Build Flatpak
Expand All @@ -56,3 +56,9 @@ jobs:
bundle: hyperplay.flatpak
manifest-path: flatpak-build/xyz.hyperplay.HyperPlay.yml
cache-key: flatpak-builder-${{ github.sha }}
- name: Upload tar xz
uses: actions/upload-artifact@v3
with:
name: linux-tar-xz
path: dist/hyperplay*.tar.xz
retention-days: 14
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
submodules: 'recursive'
token: ${{ secrets.pat }}
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
node-version: '16'
- name: Reconfigure git to use HTTP authentication
Expand Down
57 changes: 57 additions & 0 deletions .github/workflows/release_flathub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Draft Release Flathub

on:
release:
types: [published]

env:
GITHUB_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
GH_TOKEN: ${{ secrets.WORKFLOW_TOKEN }}
RELEASE_VERSION: ${{ github.ref_name }}

jobs:
draft-releases:
runs-on: ubuntu-latest
steps:
- name: echo ref name.
run: echo "tag name ${{ github.ref_name }}"
- name: Checkout repository.
uses: actions/checkout@v3
with:
submodules: 'recursive'
token: ${{ secrets.pat }}
- name: Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Reconfigure git to use HTTP authentication
run: >
git config --global url."https://github.com/".insteadOf
ssh://git@github.com/
- name: Authenticate with private NPM package
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
- name: Install modules.
run: yarn
- name: Checkout flathub repository.
run: git clone https://github.com/flathub/xyz.hyperplay.HyperPlay.git
- name: Update flathub release
run: export RELEASE_VERSION=${{ github.ref_name }} && yarn release:updateFlathub:ci
- name: Branch flathub repo
run: git checkout -b "${{ github.ref_name }}"
working-directory: ./xyz.hyperplay.HyperPlay
- name: Commit files to xyz.hyperplay.HyperPlay
run: |
git config --local user.email "27568879+BrettCleary@users.noreply.github.com"
git config --local user.name "BrettCleary"
git commit -a -m "changes for ${{ github.ref_name }}"
working-directory: ./xyz.hyperplay.HyperPlay
- name: Push updated flathub branch
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.WORKFLOW_TOKEN }}
branch: ${{ github.ref_name }}
directory: xyz.hyperplay.HyperPlay
repository: flathub/xyz.hyperplay.HyperPlay
- name: PR to flathub repo
run: sleep 5 && gh pr create --title ${{ github.ref_name }} --body ${{ github.ref_name }} --base master --head ${{ github.ref_name }}
working-directory: ./xyz.hyperplay.HyperPlay
2 changes: 1 addition & 1 deletion .github/workflows/submodules-are-merged.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
submodules: 'recursive'
token: ${{ secrets.pat }}
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
node-version: '16'
- name: Reconfigure git to use HTTP authentication
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-e2e-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
submodules: 'recursive'
token: ${{ secrets.pat }}
- name: Setup NodeJS
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Reconfigure git to use HTTP authentication
Expand All @@ -47,7 +47,7 @@ jobs:
submodules: 'recursive'
token: ${{ secrets.pat }}
- name: Setup NodeJS
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Reconfigure git to use HTTP authentication
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
submodules: 'recursive'
token: ${{ secrets.pat }}
- name: Setup NodeJS
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Reconfigure git to use HTTP authentication
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-e2e-packaged.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
submodules: 'recursive'
token: ${{ secrets.pat }}
- name: Setup NodeJS
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Reconfigure git to use HTTP authentication
Expand All @@ -48,7 +48,7 @@ jobs:
submodules: 'recursive'
token: ${{ secrets.pat }}
- name: Setup NodeJS
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Reconfigure git to use HTTP authentication
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
submodules: 'recursive'
token: ${{ secrets.pat }}
- name: Setup NodeJS
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Reconfigure git to use HTTP authentication
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
with:
submodules: 'recursive'
token: ${{ secrets.pat }}
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
node-version: '16'
- name: Reconfigure git to use HTTP authentication
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ vite-plugin-electron.log
# these can be reconfigured if we ever want to adopt yarn berry
.yarnrc.yml
.yarn/

flathub/update-flathub.js
xyz.hyperplay.HyperPlay
147 changes: 147 additions & 0 deletions flathub/update-flathub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import * as fs from 'fs'
import * as crypto from 'crypto'
import * as os from 'os'
import * as child_process from 'child_process'
import axios from 'axios'
import * as convert from 'xml-js'
import { Element } from 'xml-js'

async function main() {
console.log('tag name: ', process.env.RELEASE_VERSION)
const useTestRepo = false
const repoOrgName = useTestRepo ? 'BrettCleary' : 'HyperPlay-Gaming'
const repoName = repoOrgName + '/hyperplay-desktop-client'

// update url in xyz.hyperplay.HyperPlay.yml
console.log('updating url in xyz.hyperplay.HyperPlay.yml')
const ymlFilePath = './xyz.hyperplay.HyperPlay/xyz.hyperplay.HyperPlay.yml'
let hpYml = fs.readFileSync(ymlFilePath).toString()

const releaseString = `https://github.com/${repoName}/releases/download/${
process.env.RELEASE_VERSION
}/hyperplay-${process.env.RELEASE_VERSION?.substring(1)}.tar.xz`
hpYml = hpYml.replace(
/https:\/\/github.com\/HyperPlay-Gaming\/hyperplay-desktop-client\/releases\/download\/v.*..*..*\/hyperplay-.*..*..*.tar.xz/,
releaseString
)

// update hash in xyz.hyperplay.HyperPlay.yml from latest .tar.xz release
console.log('updating hash in xyz.hyperplay.HyperPlay.yml')
const { data } = await axios.get(
`https://api.github.com/repos/${repoName}/releases/latest`
)
const tarxz = data.assets.find((asset) =>
asset.browser_download_url.includes('tar.xz')
)
const outputFile = `${os.tmpdir()}/hyperplay.tar.xz`
child_process.spawnSync('curl', [
'-L',
tarxz.browser_download_url,
'-o',
outputFile,
'--create-dirs'
])
const outputContent = fs.readFileSync(outputFile)
const hashSum = crypto.createHash('sha512')
hashSum.update(outputContent)
const sha512 = hashSum.digest('hex')
fs.rmSync(outputFile)

hpYml = hpYml.replace(/sha512: [0-9, a-f]{128}/, `sha512: ${sha512}`)

fs.writeFileSync(ymlFilePath, hpYml)

// update release version and date on xml tag in xyz.hyperplay.HyperPlay.metainfo.xml
console.log(
'updating release version and date on xml tag in xyz.hyperplay.HyperPlay.metainfo.xml'
)
const xmlFilePath =
'./xyz.hyperplay.HyperPlay/xyz.hyperplay.HyperPlay.metainfo.xml'
let hpXml = fs.readFileSync(xmlFilePath).toString()
const date = new Date()
const isoDate = date.toISOString().slice(0, 10)

hpXml = hpXml.replace(
/release version="v.*..*..*" date="[0-9]{4}-[0-9]{2}-[0-9]{2}"/,
`release version="${process.env.RELEASE_VERSION}" date="${isoDate}"`
)

fs.writeFileSync(xmlFilePath, hpXml)
console.log(
'Finished updating flathub release! Be sure to update release notes manually before merging.'
)

// update release notes
console.log('setting default remote repo for gh cli')
const setDefaultResult = child_process.spawnSync('gh', [
'repo',
'set-default',
repoName
])
console.log('setDefaultResult stdout = ', setDefaultResult.stdout?.toString())
console.log(
'setDefaultResult stderr = ',
setDefaultResult.stderr?.toString(),
' error: ',
setDefaultResult?.error
)

const releaseNotesResult = child_process.spawnSync('gh', [
'release',
'view',
process.env.RELEASE_VERSION ?? 'undefined',
'--json',
'body'
])
const releaseNotesStdOut = releaseNotesResult.stdout?.toString()
console.log('releaseListResult stdout = ', releaseNotesStdOut)
console.log(
'releaseListResult stderr = ',
releaseNotesResult.stderr?.toString()
)

const releaseNotesJson = JSON.parse(releaseNotesStdOut)
const releaseNotesComponents = releaseNotesJson.body.split('\n')

const hpXmlJson = convert.xml2js(hpXml, { compact: false }) as Element
const releaseNotesElements: Element[] = []

for (const [i, releaseComponent_i] of releaseNotesComponents.entries()) {
//update metainfo hpXml
if (i === 0) continue
if (!releaseComponent_i.startsWith('*')) continue
if (releaseComponent_i.includes('http')) continue
const releaseNoteElement: Element = {
type: 'element',
name: 'li',
elements: [
{
type: 'text',
text: releaseComponent_i.slice(1) //remove the asterisk
}
]
}
releaseNotesElements.push(releaseNoteElement)
}

const componentsTag = hpXmlJson.elements?.[0]
const releasesTag = componentsTag?.elements?.find(
(val) => val.name === 'releases'
) //.releases.release.description.ul =
const releaseListTag =
releasesTag?.elements?.[0].elements?.[0].elements?.find(
(val) => val.name === 'ul'
)
if (releaseListTag === undefined) {
throw 'releaseListTag ul undefined'
}
releaseListTag.elements = releaseNotesElements
hpXml = convert.js2xml(hpXmlJson)
fs.writeFileSync(xmlFilePath, hpXml)

console.log(
'Finished updating flathub release! Please review and merge the flathub repo PR manually.'
)
}

main()
Loading
Loading