Feature / add tc-ready resource support #2210
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: Node CI | |
env: | |
UPDATE_RESOURCES: true | |
REPOSITORY: ${{ github.repository }} | |
REF: ${{ github.ref }} | |
on: | |
push: | |
branches: | |
- master | |
- develop | |
- release-* | |
- sandbox-* | |
pull_request: | |
branches: | |
- master | |
- develop | |
- release-* | |
- sandbox-* | |
jobs: | |
test: | |
name: Test | |
runs-on: ubuntu-latest | |
container: photonomad/github_build:latest | |
# the Dockerfile used to create this image is here: ./.github/workflows/docker/Dockerfile | |
env: | |
CI: true | |
permissions: | |
# Give the default GITHUB_TOKEN write permission to commit and push the changed files back to the repository. | |
contents: write | |
steps: | |
# - name: Dump GitHub context | |
# env: | |
# GITHUB_CONTEXT: ${{ toJson(github) }} | |
# run: echo "$GITHUB_CONTEXT" | |
- uses: actions/setup-node@v1 | |
with: | |
node-version: '16.14.2' | |
- name: Get versions | |
run: | | |
echo "node --version" | |
node --version | |
echo "npm --version" | |
npm --version | |
echo "git --version" | |
git --version | |
echo "pwd" | |
pwd | |
# - uses: actions/checkout@v2 | |
# - name: Checkout submodules | |
# shell: bash | |
# run: | | |
# auth_header="$(git config --local --get http.https://github.com/.extraheader)" | |
# git submodule sync --recursive | |
# git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 | |
- name: Checkout codebase | |
uses: actions/checkout@v3 | |
with: | |
submodules: recursive | |
persist-credentials: true | |
- name: npm install | |
run: npm ci | |
- name: List permissions | |
run: | | |
set -x | |
# create output folder with permission for tests to use for temp results | |
echo "mkdir ./src/__tests__/output" | |
mkdir ./src/__tests__/output | |
echo "chmod -R a+rwx ./src/__tests__/output" | |
chmod -R a+rwx ./src/__tests__/output | |
echo "remove git owner error" | |
git config --global --add safe.directory /__w/translationCore/translationCore | |
- name: npm test | |
run: npm run ci-test | |
- name: Upload coverage | |
run: ./node_modules/.bin/codecov -t ${{ secrets.CODECOV_TOKEN }} | |
- name: Run lint | |
run: npm run lint | |
- name: Parsing jsdocs | |
run: | | |
set -x | |
# remove jsdocs folder so it can be recreated | |
echo "rm -rf ./docs/translationCore" | |
rm -rf ./docs/translationCore | |
# give permission for jsdocs to be recreated in docs folder | |
echo "chmod -R a+rwx ./docs" | |
chmod -R a+rwx ./docs | |
ls -als ./docs | |
# update jsdocs | |
npm run doc | |
echo "ls -als ./docs/translationCore" | |
ls -als ./docs/translationCore | |
# - name: Update jsdocs in branch | |
# uses: stefanzweifel/git-auto-commit-action@v4 | |
# with: | |
# file_pattern: 'docs/*' | |
# commit_message: Apply jsdocs update | |
# skip_fetch: true | |
# skip_checkout: true | |
- uses: actions/upload-artifact@v4 | |
name: Upload jsdocs | |
with: | |
name: jsdocs | |
path: docs/ | |
build-linux: | |
name: Build Linux | |
strategy: | |
matrix: | |
trim: [ 0, 1 ] | |
needs: test | |
runs-on: ubuntu-latest | |
container: photonomad/github_build:latest | |
env: | |
TC_HELP_DESK_TOKEN: ${{ secrets.TC_HELP_DESK_TOKEN }} | |
TC_HELP_DESK_EMAIL: ${{ secrets.TC_HELP_DESK_EMAIL }} | |
APP_NAME: tC | |
CI: true | |
TRIM: ${{ matrix.trim }} | |
steps: | |
- uses: actions/setup-node@v1 | |
with: | |
node-version: '16.14.2' | |
- name: TRIM setting | |
run: echo "Trim value is $TRIM" | |
- name: Get version | |
run: | | |
echo "node --version" | |
node --version | |
echo "npm --version" | |
npm --version | |
echo "git --version" | |
git --version | |
echo "pwd" | |
pwd | |
# - uses: actions/checkout@v2 | |
# - name: Checkout submodules | |
# shell: bash | |
# run: | | |
# auth_header="$(git config --local --get http.https://github.com/.extraheader)" | |
# git submodule sync --recursive | |
# git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 | |
- name: Checkout codebase | |
uses: actions/checkout@v1 | |
with: | |
submodules: recursive | |
- name: Read version and commit sha | |
run: | | |
echo "HASH=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV | |
echo "APP_VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV | |
- name: Bundle environment variables | |
run: | | |
# work around for linux permissions restrictions: save to .env.tmp and tC build script (update_env.js) will look for that file if .env is not defined | |
touch .env.tmp | |
echo "TC_HELP_DESK_TOKEN=$TC_HELP_DESK_TOKEN" >> .env.tmp | |
echo "TC_HELP_DESK_EMAIL=$TC_HELP_DESK_EMAIL" >> .env.tmp | |
echo "BUILD=$HASH" >> .env.tmp | |
- name: npm install | |
run: npm ci | |
- name: Download latest language names | |
if: env.UPDATE_RESOURCES | |
run: | | |
# TODO: remove this fix for expired certs on uw website - hack for curl crash on invalid certs, added --insecure param | |
curl --insecure https://td.unfoldingword.org/exports/langnames.json > src/assets/langnames.json | |
- name: Before Update resources - save original manifest | |
run: cp tcResources/source-content-updater-manifest.json source-content-updater-manifest.json.orig | |
- name: Update resources | |
if: env.UPDATE_RESOURCES | |
# add automatic retry | |
uses: nick-invision/retry@v2 | |
with: | |
timeout_minutes: 20 | |
max_attempts: 3 | |
retry_on: error | |
command: npm run update-resources | |
# restore original manifest before retry | |
on_retry_command: cp source-content-updater-manifest.json.orig tcResources/source-content-updater-manifest.json | |
- name: Trim resources | |
if: ${{ env.TRIM == '1' }} | |
run: npm run minimal-resources | |
- name: build linux | |
id: build | |
run: | | |
echo "Building $APP_VERSION-$HASH" | |
npm run build-linux | |
# arm64 | |
- name: Set arm64 MAX artifact name | |
run: echo "ARTIFACT_ARM64=$(echo "$APP_NAME-linux-arm64-$APP_VERSION-MAX-$HASH.deb")" >> $GITHUB_ENV | |
- name: Set arm64 LITE artifact name | |
if: ${{ env.TRIM == '1' }} | |
run: echo "ARTIFACT_ARM64=$(echo "$APP_NAME-linux-arm64-$APP_VERSION-LITE-$HASH.deb")" >> $GITHUB_ENV | |
- name: bundle arm64 linux | |
run: ./node_modules/.bin/gulp release-linux-deb-arm64 --out=artifacts/arm64/$ARTIFACT_ARM64 | |
- uses: actions/upload-artifact@v4 | |
name: Upload arm64 artifacts | |
with: | |
name: ${{ env.ARTIFACT_ARM64 }} | |
path: artifacts/arm64/ | |
# x64 | |
- name: Set x64 MAX artifact name | |
run: echo "ARTIFACT_X64=$(echo "$APP_NAME-linux-x64-$APP_VERSION-MAX-$HASH.deb")" >> $GITHUB_ENV | |
- name: Set x64 LITE artifact name | |
if: ${{ env.TRIM == '1' }} | |
run: echo "ARTIFACT_X64=$(echo "$APP_NAME-linux-x64-$APP_VERSION-LITE-$HASH.deb")" >> $GITHUB_ENV | |
- name: bundle x64 linux | |
run: ./node_modules/.bin/gulp release-linux-deb --out=artifacts/x64/$ARTIFACT_X64 | |
- uses: actions/upload-artifact@v4 | |
name: Upload x64 artifacts | |
with: | |
name: ${{ env.ARTIFACT_X64 }} | |
path: artifacts/x64/ | |
build-windows: | |
name: Build Windows | |
strategy: | |
matrix: | |
trim: [ 0, 1 ] | |
needs: test | |
runs-on: windows-2019 | |
env: | |
TC_HELP_DESK_TOKEN: ${{ secrets.TC_HELP_DESK_TOKEN }} | |
TC_HELP_DESK_EMAIL: ${{ secrets.TC_HELP_DESK_EMAIL }} | |
APP_NAME: tC | |
CI: true | |
TRIM: ${{ matrix.trim }} | |
steps: | |
- uses: actions/setup-node@v1 | |
with: | |
node-version: '16.14.2' | |
- name: TRIM setting | |
run: echo "Trim value is $TRIM" | |
shell: bash | |
- name: Node version | |
run: | | |
node --version | |
npm --version | |
- uses: actions/checkout@v2 | |
- name: Checkout submodules | |
shell: bash | |
run: | | |
auth_header="$(git config --local --get http.https://github.com/.extraheader)" | |
git submodule sync --recursive | |
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 | |
- name: Read version and commit sha | |
run: | | |
echo "HASH=$(node -p -e "'${{ github.sha }}'.substring(0, 7)")" >> $GITHUB_ENV | |
echo "APP_VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV | |
shell: bash | |
- name: Bundle environment variables | |
run: | | |
touch .env | |
echo "TC_HELP_DESK_TOKEN=${{ env.TC_HELP_DESK_TOKEN }}" >> .env | |
echo "TC_HELP_DESK_EMAIL=${{ env.TC_HELP_DESK_EMAIL }}" >> .env | |
echo "BUILD=${{ env.HASH }}" >> .env | |
- name: npm install | |
run: | | |
npm ci | |
npm run update-env | |
shell: bash | |
- name: Download latest language names | |
if: env.UPDATE_RESOURCES | |
run: curl https://td.unfoldingword.org/exports/langnames.json > src/assets/langnames.json | |
- name: Before Update resources - save original manifest | |
shell: bash | |
run: cp tcResources/source-content-updater-manifest.json source-content-updater-manifest.json.orig | |
- name: Update resources | |
if: env.UPDATE_RESOURCES | |
# add automatic retry | |
uses: nick-invision/retry@v2 | |
with: | |
timeout_minutes: 20 | |
max_attempts: 3 | |
retry_on: error | |
shell: bash | |
command: npm run update-resources | |
# restore original manifest before retry | |
on_retry_command: cp source-content-updater-manifest.json.orig tcResources/source-content-updater-manifest.json | |
- name: Trim resources | |
if: ${{ env.TRIM == '1' }} | |
run: npm run minimal-resources | |
shell: bash | |
- name: build windows | |
run: | | |
echo "Building $APP_VERSION-$HASH" | |
npm run build-win | |
# x64 | |
- name: Set x64 MAX artifact name | |
run: echo "ARTIFACT_X64=$(echo "${{ env.APP_NAME }}-win-x64-${{ env.APP_VERSION }}-MAX-${{ env.HASH }}.exe")" >> $GITHUB_ENV | |
shell: bash | |
- name: Set x64 LITE artifact name | |
if: ${{ env.TRIM == '1' }} | |
run: echo "ARTIFACT_X64=$(echo "${{ env.APP_NAME }}-win-x64-${{ env.APP_VERSION }}-LITE-${{ env.HASH }}.exe")" >> $GITHUB_ENV | |
shell: bash | |
- name: bundle x64 windows | |
run: | | |
echo "Generating executable artifacts/x64/${{ env.ARTIFACT_X64 }}" | |
./node_modules/.bin/gulp release-win64 --out=artifacts/x64/${{ env.ARTIFACT_X64 }} | |
# - name: list directories | |
# run: | | |
# dir . | |
# dir ../ | |
# dir ../artifacts | |
- uses: actions/upload-artifact@v4 | |
name: Upload x64 artifacts | |
with: | |
name: ${{ env.ARTIFACT_X64 }} | |
path: artifacts/x64/ | |
# x32 | |
- name: Set x32 MAX artifact name | |
run: echo "ARTIFACT_X32=$(echo "${{ env.APP_NAME }}-win-x32-${{ env.APP_VERSION }}-MAX-${{ env.HASH }}.exe")" >> $GITHUB_ENV | |
shell: bash | |
- name: Set x32 LITE artifact name | |
if: ${{ env.TRIM == '1' }} | |
run: echo "ARTIFACT_X32=$(echo "${{ env.APP_NAME }}-win-x32-${{ env.APP_VERSION }}-LITE-${{ env.HASH }}.exe")" >> $GITHUB_ENV | |
shell: bash | |
- name: bundle x32 windows | |
run: | | |
echo "Generating executable artifacts/x32/${{ env.ARTIFACT_X32 }}" | |
./node_modules/.bin/gulp release-win32 --out=artifacts/x32/${{ env.ARTIFACT_X32 }} | |
- uses: actions/upload-artifact@v4 | |
name: Upload x32 artifacts | |
with: | |
name: ${{ env.ARTIFACT_X32 }} | |
path: artifacts/x32/ | |
build-macos: | |
name: Build macOS | |
strategy: | |
matrix: | |
trim: [ 0, 1 ] | |
needs: test | |
runs-on: macos-latest | |
env: | |
TC_HELP_DESK_TOKEN: ${{ secrets.TC_HELP_DESK_TOKEN }} | |
TC_HELP_DESK_EMAIL: ${{ secrets.TC_HELP_DESK_EMAIL }} | |
APP_NAME: tC | |
CI: true | |
TRIM: ${{ matrix.trim }} | |
steps: | |
- uses: actions/setup-node@v1 | |
with: | |
node-version: '16.14.2' | |
- name: TRIM setting | |
run: echo "Trim value is $TRIM" | |
- name: add Delay | |
if: ${{ env.TRIM == '1' }} | |
run: sleep 60 | |
shell: bash | |
- name: Node version | |
run: | | |
node --version | |
npm --version | |
- uses: actions/checkout@v2 | |
- name: Checkout submodules | |
shell: bash | |
run: | | |
auth_header="$(git config --local --get http.https://github.com/.extraheader)" | |
git submodule sync --recursive | |
git -c "http.extraheader=$auth_header" -c protocol.version=2 submodule update --init --force --recursive --depth=1 | |
# - name: Checkout codebase | |
# uses: actions/checkout@v1 | |
# with: | |
# submodules: recursive | |
- name: Read version and commit sha | |
run: | | |
echo "HASH=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV | |
echo "APP_VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV | |
- name: Bundle environment variables | |
run: | | |
touch .env | |
echo "TC_HELP_DESK_TOKEN=$TC_HELP_DESK_TOKEN" >> .env | |
echo "TC_HELP_DESK_EMAIL=$TC_HELP_DESK_EMAIL" >> .env | |
echo "BUILD=$HASH" >> .env | |
- name: npm install | |
run: | | |
npm ci | |
npm run update-env | |
- name: Download latest language names | |
if: env.UPDATE_RESOURCES | |
run: curl https://td.unfoldingword.org/exports/langnames.json > src/assets/langnames.json | |
- name: Before Update resources - save original manifest | |
run: cp tcResources/source-content-updater-manifest.json source-content-updater-manifest.json.orig | |
- name: Update resources | |
if: env.UPDATE_RESOURCES | |
# add automatic retry | |
uses: nick-invision/retry@v2 | |
with: | |
timeout_minutes: 20 | |
max_attempts: 3 | |
retry_on: error | |
command: npm run update-resources | |
# restore original manifest before retry | |
on_retry_command: cp source-content-updater-manifest.json.orig tcResources/source-content-updater-manifest.json | |
- name: Trim resources | |
if: ${{ env.TRIM == '1' }} | |
run: npm run minimal-resources | |
- name: build macOS | |
id: build | |
run: | | |
echo "Building $APP_VERSION-$HASH" | |
npm run build-macos | |
# x64 | |
- name: Set x64 MAX artifact name | |
run: echo "ARTIFACT_X64=$(echo "$APP_NAME-macos-x64-$APP_VERSION-MAX-$HASH.dmg")" >> $GITHUB_ENV | |
- name: Set x64 LITE artifact name | |
if: ${{ env.TRIM == '1' }} | |
run: echo "ARTIFACT_X64=$(echo "$APP_NAME-macos-x64-$APP_VERSION-LITE-$HASH.dmg")" >> $GITHUB_ENV | |
- name: bundle x64 macOS | |
run: ./node_modules/.bin/gulp release-macos --out=artifacts/x64/$ARTIFACT_X64 | |
- uses: actions/upload-artifact@v4 | |
name: Upload x64 artifacts | |
with: | |
name: ${{ env.ARTIFACT_X64 }} | |
path: artifacts/x64/ | |
# universal build | |
- name: Set universal MAX artifact name | |
run: echo "ARTIFACT_UNIV=$(echo "$APP_NAME-macos-universal-$APP_VERSION-MAX-$HASH.dmg")" >> $GITHUB_ENV | |
- name: Set universal LITE artifact name | |
if: ${{ env.TRIM == '1' }} | |
run: echo "ARTIFACT_UNIV=$(echo "$APP_NAME-macos-universal-$APP_VERSION-LITE-$HASH.dmg")" >> $GITHUB_ENV | |
- name: bundle universal macOS | |
run: ./node_modules/.bin/gulp release-macos-universal --out=artifacts/universal/$ARTIFACT_UNIV | |
- uses: actions/upload-artifact@v4 | |
name: Upload universal artifacts | |
with: | |
name: ${{ env.ARTIFACT_UNIV }} | |
path: artifacts/universal/ | |
notify: | |
name: Notify | |
needs: [build-macos, build-windows, build-linux] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get short hash | |
run: | | |
echo "SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV | |
# - name: Dump GitHub context | |
# env: | |
# GITHUB_CONTEXT: ${{ toJson(github) }} | |
# run: echo "$GITHUB_CONTEXT" | |
- name: Notify Zulip of pull request | |
if: github.event_name == 'pull_request' | |
env: | |
TOKEN: ${{ secrets.ZULIP_TOKEN }} | |
USER: [email protected] | |
ORG: unfoldingword | |
CHANNEL: SOFTWARE - UR/github | |
SUBJECT: tC builds | |
PR_NUMBER: ${{ github.event.number }} | |
PR_TITLE: ${{ github.event.pull_request.title }} | |
run: | | |
curl -o /dev/null -s -X POST https://$ORG.zulipchat.com/api/v1/messages \ | |
-u $USER:$TOKEN \ | |
-d "type=stream" \ | |
-d "to=$CHANNEL" \ | |
-d "subject=$SUBJECT" \ | |
-d "content=Pull request [$PR_TITLE #$PR_NUMBER](https://github.com/$REPOSITORY/pull/$PR_NUMBER) has new builds based on [$SHORT_SHA](https://github.com/$REPOSITORY/pull/$PR_NUMBER/commits/$GITHUB_SHA). | |
You can view logs and download artifacts from the [Checks](https://github.com/$REPOSITORY/pull/$PR_NUMBER/checks?sha=$GITHUB_SHA) tab." | |
- name: Get branch name | |
if: github.event_name == 'push' | |
run: echo "BRANCH=$(node -p -e "'$REF'.substr(11)")" >> $GITHUB_ENV # strips off "refs/heads/" | |
- name: Notify Zulip of push | |
if: github.event_name == 'push' | |
env: | |
TOKEN: ${{ secrets.ZULIP_TOKEN }} | |
USER: [email protected] | |
ORG: unfoldingword | |
CHANNEL: SOFTWARE - UR/github | |
SUBJECT: tC builds | |
run: | | |
curl -o /dev/null -s -X POST https://$ORG.zulipchat.com/api/v1/messages \ | |
-u $USER:$TOKEN \ | |
-d "type=stream" \ | |
-d "to=$CHANNEL" \ | |
-d "subject=$SUBJECT" \ | |
-d "content=Branch [$BRANCH](https://github.com/$REPOSITORY/tree/$BRANCH) has new builds based on [$SHORT_SHA](https://github.com/$REPOSITORY/commit/$GITHUB_SHA). | |
You can view logs and download artifacts from the [Actions](https://github.com/$REPOSITORY/commit/$GITHUB_SHA/checks) tab." |