Skip to content

build

build #212

Workflow file for this run

name: build
on:
workflow_run:
workflows: [ci]
types: ["completed"]
branches: [main, release]
concurrency:
group: ${{ github.workflow }}-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: true
jobs:
info:
name: Collect information
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion != 'failure' && github.event.repository.full_name == 'reearth/reearth-marketplace' && (github.event.workflow_run.head_branch == 'release' || !startsWith(github.event.head_commit.message, 'v'))
outputs:
sha_short: ${{ steps.info.outputs.sha_short }}
new_tag: ${{ steps.info.outputs.new_tag}}
new_tag_short: ${{ steps.info.outputs.new_tag_short }}
name: ${{ steps.info.outputs.name }}
steps:
- name: checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.workflow_run.head_sha }}
- name: fetch tags
run: git fetch --prune --unshallow --tags
- name: Get info
id: info
env:
BRANCH: ${{ github.event.workflow_run.head_branch }}
run: |
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
if [[ "$BRANCH" = "release" ]]; then
TAG=$(git tag --points-at HEAD)
if [[ ! -z "$TAG" ]]; then
echo "::set-output name=new_tag::$TAG"
echo "::set-output name=new_tag_short::${TAG#v}"
else
echo "::set-output name=name::rc"
fi
else
echo "::set-output name=name::nightly"
fi
- name: Show info
env:
SHA_SHORT: ${{ steps.info.outputs.sha_short }}
NEW_TAG: ${{ steps.info.outputs.new_tag }}
NEW_TAG_SHORT: ${{ steps.info.outputs.new_tag_short }}
NAME: ${{ steps.info.outputs.name }}
run: echo "sha_short=$SHA_SHORT, new_tag=$NEW_TAG, new_tag_short=$NEW_TAG_SHORT, name=$NAME"
build:
name: Build and release nightly/rc
runs-on: ubuntu-latest
needs:
- info
if: needs.info.outputs.name || needs.info.outputs.new_tag
env:
# ARTIFACTS_SERVER: server/dist #TODO: fix here
ARTIFACTS_WEB: reearth-marketplace-web_${{ needs.info.outputs.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 }}
- name: get latest web artifact
uses: dawidd6/action-download-artifact@v2
with:
github_token: ${{ steps.app-token.outputs.token }}
workflow: ci.yml
workflow_conclusion: success
branch: ${{ github.event.workflow_run.head_branch }}
name: reearth-marketplace-web
check_artifacts: true
search_artifacts: true
- name: rename artifact
run: mv reearth-marketplace-web.tar.gz $ARTIFACTS_WEB
- name: Release nightly/rc
if: needs.info.outputs.name
uses: ncipollo/release-action@v1
with:
allowUpdates: true
artifactErrorsFailBuild : true
artifacts: ${{ env.ARTIFACTS_WEB }}
# artifacts: ${{ env.ARTIFACTS_SERVER }},${{ env.ARTIFACTS_WEB }}
commit: ${{ github.sha }}
name: ${{ needs.info.outputs.name }}
tag: ${{ needs.info.outputs.name }}
body: ${{ github.sha }}
prerelease: true
# This is for stable release with version tags
- name: Dowload latest changelog
if: needs.info.outputs.new_tag
uses: dawidd6/action-download-artifact@v2
with:
workflow: release.yml
name: changelog-${{ needs.info.outputs.new_tag }}
- name: Create GitHub release
if: needs.info.outputs.new_tag
uses: ncipollo/release-action@v1
with:
#TODO: サーバー側のartifactを修正
artifacts: ${{ env.ARTIFACTS_WEB }}
commit: ${{ github.sha }}
name: ${{ needs.info.outputs.new_tag }}
tag: ${{ needs.info.outputs.new_tag }}
bodyFile: CHANGELOG_latest.md
docker:
name: Build and push Docker image
runs-on: ubuntu-latest
needs:
- info
if: needs.info.outputs.name || needs.info.outputs.new_tag
env:
IMAGE_NAME: reearth/reearth-marketplace
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
- 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: ${{ needs.info.outputs.new_tag_short }}
NAME: ${{ needs.info.outputs.name }}
SHA: ${{ needs.info.outputs.sha_short }}
run: |
if [[ -n $TAG ]]; then
PLATFORMS=linux/amd64
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: Download web arfiacts
uses: dawidd6/action-download-artifact@v2
with:
github_token: ${{ steps.app-token.outputs.token }}
workflow: ci.yml
workflow_conclusion: success
branch: ${{ github.event.workflow_run.head_branch }}
name: reearth-marketplace-web
check_artifacts: true
- name: Extract
run: tar -xvf reearth-marketplace-web.tar.gz && mv reearth-marketplace-web server/web
- name: Build and load docker image
uses: docker/build-push-action@v3
with:
context: ./server
platforms: ${{ steps.options.outputs.platforms }}
load: true
build-args: VERSION=${{ steps.options.outputs.version }}
tags: ${{ steps.options.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Push docker images
run: docker push ${{ steps.options.outputs.tags }}
- name: Make dir
run: mkdir reearth
- name: Save docker image
run: docker save ${{ steps.options.outputs.tags }} | gzip > reearth-marketplace.tar.gz
- name: Save imaged to artifact
uses: actions/upload-artifact@v4
# env:
# TAG: ${{ needs.info.outputs.tag_short }}
# NAME: ${{ needs.info.outputs.name }}
with:
name: reearth-marketplace
# name: '[ -n $TAG ] && echo reearth-marketplace_$TAG || echo reearth-marketplace_$'
path: reearth-marketplace.tar.gz
if-no-files-found: error
# TODO: invoke deploy test env if name == "nightly" with workflow_call event