Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

feat: remesh package source control #339

feat: remesh package source control

feat: remesh package source control #339

Workflow file for this run

# The purpose of this workflow is to fully publish new releases.
# It builds, tests, and publishes a new release along with its changelog.
name: electron-ci
on:
push:
branches:
- main
- develop
jobs:
build-and-publish:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-latest]
include:
- os: windows-latest
build_command: "buildwin"
artifact_name: "fsolauncher-win"
- os: macos-latest
build_command: "builddarwin"
artifact_name: "fsolauncher-mac"
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Replace Sentry DSN and Browser Loader (Windows)
if: matrix.os == 'windows-latest'
working-directory: src
run: |
(Get-Content sentry.config.js) -replace "SENTRY_CI_DSN", "${{ secrets.SENTRY_CI_DSN }}" | Set-Content sentry.config.js
(Get-Content sentry.config.js) -replace "SENTRY_CI_BROWSER_LOADER", "${{ secrets.SENTRY_CI_BROWSER_LOADER }}" | Set-Content sentry.config.js
- name: Replace Sentry DSN and Browser Loader (macOS)
if: matrix.os == 'macos-latest'
working-directory: src
run: |
sed "s#SENTRY_CI_DSN#${{ secrets.SENTRY_CI_DSN }}#g" sentry.config.js > sentry.config.temp.js
mv sentry.config.temp.js sentry.config.js
sed "s#SENTRY_CI_BROWSER_LOADER#${{ secrets.SENTRY_CI_BROWSER_LOADER }}#g" sentry.config.js > sentry.config.temp.js
mv sentry.config.temp.js sentry.config.js
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 16
- name: Cache Electron binaries
id: cache-electron-binaries
uses: actions/cache@v2
with:
path: |
~/.electron
~/Library/Caches/electron
~/AppData/Local/electron/Cache/
key: ${{ runner.os }}-electron-binaries-${{ hashFiles('src/package-lock.json') }}
restore-keys: |
${{ runner.os }}-electron-binaries-
- name: Cache Node.js modules
id: cache-node-modules
uses: actions/cache@v2
with:
path: src/node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('src/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-modules-
- name: Playwright Skip Browser Download
run: echo "PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1" >> $GITHUB_ENV
- name: python3 fix
if: matrix.os == 'macos-latest'
run: python3 -m pip install setuptools
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci
working-directory: src
- name: Run ESLint
run: npm run lint
working-directory: src
- name: Build
run: npm run ${{ matrix.build_command }}
working-directory: src
- name: Run e2e tests
run: npm run test
env:
GITHUB_RATELIMIT_TOKEN: ${{ secrets.GITHUB_TOKEN }}
working-directory: src
- name: Calculate hashes and save to files (Windows)
if: matrix.os == 'windows-latest'
shell: powershell
run: |
$hash = (Get-FileHash -Path "release/FreeSO Launcher Setup.exe" -Algorithm SHA256).Hash.ToLower()
echo "Windows hash: $hash"
Set-Content -Path "release/sha256_win32.txt" -Value $hash
- name: Calculate hashes and save to files (macOS)
if: matrix.os == 'macos-latest'
run: |
hash=$(shasum -a 256 release/FreeSO\ Launcher.dmg | awk '{print $1}')
echo "macOS hash: $hash"
echo $hash > release/sha256_darwin.txt
- name: List contents of the release directory (Windows)
if: matrix.os == 'windows-latest'
run: |
dir "release"
- name: List contents of the release directory (macOS)
if: matrix.os == 'macos-latest'
run: |
ls -la release
- name: Upload artifacts (Windows)
uses: actions/upload-artifact@v2
if: matrix.os == 'windows-latest'
with:
name: ${{ matrix.artifact_name }}
path: |
release/FreeSO Launcher Setup.exe
release/sha256_win32.txt
- name: Upload artifacts (macOS)
uses: actions/upload-artifact@v2
if: matrix.os == 'macos-latest'
with:
name: ${{ matrix.artifact_name }}
path: |
release/FreeSO Launcher.dmg
release/sha256_darwin.txt
create-release:
needs: build-and-publish
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Get version
uses: nyaa8/package-version@v1
with:
path: 'src/package.json'
follow-symlinks: 'false'
- name: Calculate release type counter
id: release_type_counter
run: |
git fetch --prune --unshallow --tags
release_type="alpha"
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
release_type="prod"
fi
echo "RELEASE_TYPE=$release_type" >> $GITHUB_ENV
tags_with_counter=$(git tag --list | grep -E "^${{ env.PACKAGE_VERSION }}-${release_type}\.[0-9]+$" || true)
max_counter=0
for tag in $tags_with_counter; do
current_counter=$(echo $tag | sed -E "s/^${{ env.PACKAGE_VERSION }}-${release_type}\.([0-9]+)$/\1/")
if [[ $current_counter -gt $max_counter ]]; then
max_counter=$current_counter
fi
done
counter=$((max_counter + 1))
echo "COUNTER=$counter" >> $GITHUB_ENV
full_version_name="${{ env.PACKAGE_VERSION }}-$release_type.$counter"
echo "FULL_VERSION_NAME=$full_version_name" >> $GITHUB_ENV
- name: Get latest release tag
id: latest_release_tag
run: |
if [ "${{ env.RELEASE_TYPE }}" == "alpha" ]; then
latest_release_tag=$(git tag --sort=committerdate | grep -E "alpha\.[0-9]+$" | tail -1)
else
latest_release_tag=$(git tag --sort=committerdate | grep -E "prod\.[0-9]+$" | tail -1)
fi
echo "LATEST_RELEASE_TAG=$latest_release_tag" >> $GITHUB_ENV
- name: Generate release notes
id: release_notes
run: |
if [ "${{ env.RELEASE_TYPE }}" == "alpha" ]; then
release_notes="This is a pre-release version meant for development and testing."
else
release_notes="This is a stable release suitable for reliable end-user experience and optimized for production use."
fi
commit_count=$(git rev-list --count ${{ env.LATEST_RELEASE_TAG }}..HEAD)
if [ "$commit_count" != "0" ]; then
if [ "$commit_count" == "1" ]; then
changes_word="change"
verb="has"
else
changes_word="changes"
verb="have"
fi
release_notes=$(printf "%s\n\nThere %s been %s %s since the last release. See the [list of changes](https://github.com/${{ github.repository }}/compare/${{ env.LATEST_RELEASE_TAG }}...${{ env.FULL_VERSION_NAME }})." "$release_notes" "$verb" "$commit_count" "$changes_word")
fi
echo "$release_notes" > release_notes.txt
- name: Create release
id: create_release
uses: softprops/action-gh-release@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: ${{ env.FULL_VERSION_NAME }}
name: Release ${{ env.FULL_VERSION_NAME }}
body_path: release_notes.txt
draft: false
prerelease: ${{ github.ref != 'refs/heads/main' }}
- name: Download artifacts (Windows)
uses: actions/download-artifact@v2
with:
name: fsolauncher-win
path: release/win
- name: Download artifacts (macOS)
uses: actions/download-artifact@v2
with:
name: fsolauncher-mac
path: release/mac
- name: Upload release assets
uses: actions/github-script@v5
with:
script: |
const fs = require('fs');
const assetPaths = [
{path: 'release/win/FreeSO Launcher Setup.exe', name: `fsolauncher-${process.env.FULL_VERSION_NAME}.exe`, contentType: 'application/octet-stream'},
{path: 'release/win/sha256_win32.txt', name: `sha256-win32-${process.env.FULL_VERSION_NAME}.txt`, contentType: 'text/plain'},
{path: 'release/mac/FreeSO Launcher.dmg', name: `fsolauncher-${process.env.FULL_VERSION_NAME}.dmg`, contentType: 'application/octet-stream'},
{path: 'release/mac/sha256_darwin.txt', name: `sha256-darwin-${process.env.FULL_VERSION_NAME}.txt`, contentType: 'text/plain'}
];
const release = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: process.env.FULL_VERSION_NAME,
});
for (const asset of assetPaths) {
const content = fs.readFileSync(asset.path);
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.data.id,
name: asset.name,
data: content,
headers: {
'content-type': asset.contentType,
'content-length': content.length
}
});
}
github-token: ${{ secrets.GITHUB_TOKEN }}