Skip to content

build-web

build-web #593

Workflow file for this run

name: build-web
on:
workflow_dispatch:
inputs:
sha_short:
description: 'sha_short'
required: true
new_tag:
description: 'new_tag'
required: true
new_tag_short:
description: 'new_tag_short'
required: true
name:
description: 'name'
required: true
sha:
description: "sha"
required: true
repository_dispatch:
types: [build-web]
jobs:
build-web:
name: Build
runs-on: ubuntu-latest
defaults:
run:
working-directory: web
if: github.event.inputs.name
env:
NODE_OPTIONS: "--max-old-space-size=8192"
steps:
- uses: actions/setup-node@v3
with:
node-version: lts/*
- uses: actions/checkout@v3
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install
run: yarn install
- name: Build
run: yarn build
- name: Pack
run: mv dist reearth-web && tar -zcvf reearth-web.tar.gz reearth-web
- uses: actions/upload-artifact@v2
with:
name: reearth-web
path: web/reearth-web.tar.gz
release-nightly:
name: Release nightly/rc
runs-on: ubuntu-latest
needs: [build-web]
if: ${{ github.event.inputs.name != 'blank' }}
env:
ARTIFACT: reearth-web_${{ github.event.inputs.name }}.tar.gz
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
- uses: actions/download-artifact@v2
with:
name: reearth-web
- name: Rename artifact
run: mv reearth-web.tar.gz $ARTIFACT
- name: Release
uses: ncipollo/release-action@v1
with:
allowUpdates: true
artifacts: ${{ env.ARTIFACT }}
artifactContentType: application/gzip
commit: ${{ github.event.inputs.sha }}
name: ${{ github.event.inputs.name }}
tag: ${{ github.event.inputs.name }}
body: ${{ github.event.inputs.sha }}
prerelease: true
- name: Invoke ci-deploy-web-nightly workflow
uses: benc-uk/workflow-dispatch@v1
if: github.event.inputs.name == 'nightly'
with:
workflow: deploy-web-nightly
token: ${{ steps.app-token.outputs.token }}
build-docker-image:
name: Build and push Docker image
runs-on: ubuntu-latest
needs: [release-nightly]
if: ${{ github.event.inputs.name != 'blank' || github.event.inputs.new_tag != 'blank' }}
env:
IMAGE_NAME: reearth/reearth-visualizer
defaults:
run:
working-directory: server
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get options
id: options
env:
TAG: ${{ github.event.inputs.new_tag_short && github.event.inputs.new_tag_short != 'blank' && github.event.inputs.new_tag_short || '' }}
NAME: ${{ github.event.inputs.name }}
SHA: ${{ github.event.inputs.sha_short }}
run: |
if [[ -n $TAG ]]; then
PLATFORMS=linux/amd64,linux/arm64
VERSION=$TAG
TAGS=$IMAGE_NAME:$TAG
if [[ ! $TAG =~ '-' ]]; then
TAGS+=,${IMAGE_NAME}:${TAG%.*}
TAGS+=,${IMAGE_NAME}:${TAG%%.*}
TAGS+=,${IMAGE_NAME}:latest
fi
else
PLATFORMS=linux/amd64
VERSION=$SHA
TAGS=$IMAGE_NAME:$NAME
fi
echo "::set-output name=platforms::$PLATFORMS"
echo "::set-output name=version::$VERSION"
echo "::set-output name=tags::$TAGS"
- name: Fetch reearth-web release
uses: dsaltares/fetch-gh-release-asset@master
with:
repo: reearth/reearth
version: tags/${{ github.event.inputs.name && github.event.inputs.name != 'blank' && github.event.inputs.name || github.event.inputs.new_tag }}
file: reearth-web_${{ github.event.inputs.name && github.event.inputs.name != 'blank' && github.event.inputs.name || github.event.inputs.new_tag }}.tar.gz
token: ${{ secrets.GITHUB_TOKEN }}
target: server/reearth-web.tar.gz
- name: Extract reearth/web
run: tar -xvf reearth-web.tar.gz; mv reearth-web web; ls
- name: Build and push docker image
uses: docker/build-push-action@v2
with:
context: server
platforms: ${{ steps.options.outputs.platforms }}
push: true
build-args: VERSION=${{ steps.options.outputs.version }}
tags: ${{ steps.options.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
release:
name: Release
runs-on: ubuntu-latest
if: ${{ github.event.inputs.new_tag != 'blank' }}
env:
ARTIFACT: reearth-web_${{ github.event.inputs.new_tag }}.tar.gz
steps:
- name: Fetch reearth-web release
uses: dsaltares/fetch-gh-release-asset@master
with:
version: tags/rc
file: reearth-web_rc.tar.gz
token: ${{ secrets.GITHUB_TOKEN }}
- name: Rename artifact
run: mv reearth-web_rc.tar.gz $ARTIFACT
- name: Download latest changelog
uses: dawidd6/action-download-artifact@v2
with:
workflow: release.yml
name: changelog-${{ github.event.inputs.new_tag }}
- name: Create GitHub release
uses: ncipollo/release-action@v1
with:
allowUpdates: true
artifacts: ${{ env.ARTIFACT }}
artifactContentType: application/gzip
commit: ${{ github.event.inputs.sha }}
name: ${{ github.event.inputs.new_tag }}
tag: ${{ github.event.inputs.new_tag }}
bodyFile: CHANGELOG_latest.md