build-server #49
This file contains hidden or 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: build-server | |
| 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-server] | |
| jobs: | |
| build-server: | |
| name: Build and release server | |
| runs-on: ubuntu-latest | |
| if: github.event.inputs.name || github.event.inputs.new_tag | |
| env: | |
| ARTIFACTS: server/dist/reearth_*.* | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Go | |
| uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 | |
| with: | |
| go-version-file: 'server/go.mod' | |
| - name: Run GoReleaser | |
| uses: goreleaser/goreleaser-action@5fdedb94abba051217030cc86d4523cf3f02243d # v4.6.0 | |
| with: | |
| distribution: goreleaser | |
| version: latest | |
| args: release ${{ github.event.inputs.new_tag == 'blank' && '--snapshot' || '' }} | |
| workdir: server | |
| env: | |
| GORELEASER_CURRENT_TAG: ${{ github.event.inputs.new_tag == 'blank' && '0.0.0' || github.event.inputs.new_tag }} | |
| - name: Rename artifacts | |
| if: ${{ github.event.inputs.name != 'blank' }} | |
| run: | | |
| for f in $ARTIFACTS; do | |
| newname=$(echo $f | sed -E 's/_0\.0\.0-SNAPSHOT-[^_]*/_${{ github.event.inputs.name }}/') | |
| if [ "$f" != "$newname" ]; then | |
| mv "$f" "$newname" | |
| fi | |
| done | |
| - name: List artifacts | |
| run: ls -l server/dist | |
| - name: Release nightly/rc | |
| if: ${{ github.event.inputs.name != 'blank' }} | |
| uses: ncipollo/release-action@440c8c1cb0ed28b9f43e4d1d670870f059653174 # v1.16.0 | |
| with: | |
| allowUpdates: true | |
| artifacts: ${{ env.ARTIFACTS }} | |
| commit: ${{ github.event.inputs.sha }} | |
| name: ${{ github.event.inputs.name }} | |
| tag: ${{ github.event.inputs.name }} | |
| body: ${{ github.event.inputs.sha_short }} | |
| prerelease: true | |
| - name: Download latest changelog | |
| if: ${{ github.event.inputs.new_tag != 'blank' }} | |
| uses: dawidd6/action-download-artifact@268677152d06ba59fcec7a7f0b5d961b6ccd7e1e # v2.28.0 | |
| with: | |
| workflow: release.yml | |
| name: changelog-${{ github.event.inputs.new_tag }} | |
| - name: Create GitHub release | |
| if: ${{ github.event.inputs.new_tag != 'blank' }} | |
| uses: ncipollo/release-action@440c8c1cb0ed28b9f43e4d1d670870f059653174 # v1.16.0 | |
| with: | |
| allowUpdates: true | |
| artifacts: ${{ env.ARTIFACTS }} | |
| commit: ${{ github.event.inputs.sha }} | |
| name: ${{ github.event.inputs.new_tag }} | |
| tag: ${{ github.event.inputs.new_tag}} | |
| bodyFile: CHANGELOG_latest.md | |
| build-docker-image: | |
| name: Build and push Docker image | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.inputs.name != 'blank' || github.event.inputs.new_tag != 'blank' }} | |
| env: | |
| IMAGE_NAME: reearth/reearth | |
| defaults: | |
| run: | |
| working-directory: server | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0 | |
| - uses: actions/create-github-app-token@d72941d797fd3113feb6b93fd0dec494b13a2547 # v1.12.0 | |
| 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@2b82ce82d56a2a04d2637cd93a637ae1b359c0a7 # v2.2.0 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@885d1462b80bc1c1c7f0b00334ad271f09369c55 # v2.10.0 | |
| - name: Login to DockerHub | |
| uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0 | |
| 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-classic | |
| 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@ac9327eae2b366085ac7f6a2d02df8aa8ead720a # v2.10.0 | |
| 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 | |
| - name: Invoke ci-deploy-server-nightly workflow | |
| uses: benc-uk/workflow-dispatch@e2e5e9a103e331dad343f381a29e654aea3cf8fc # v1.2.4 | |
| if: github.event.inputs.name == 'nightly' | |
| with: | |
| workflow: deploy-server-nightly | |
| token: ${{ steps.app-token.outputs.token }} |