Skip to content

Commit

Permalink
ci: set up workflows which generate changelog, trigger GitHub's relea…
Browse files Browse the repository at this point in the history
…se and save rc to the artifacts (#42)
  • Loading branch information
HideBa authored Sep 13, 2022
1 parent 61d4b10 commit c57a831
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 8 deletions.
64 changes: 56 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ on:
workflow_run:
workflows: [ci]
types: ["completed"]
branches: ["main"]
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 == 'main'
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}}
Expand All @@ -22,12 +25,18 @@ jobs:
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)"
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}"
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
Expand All @@ -38,7 +47,45 @@ jobs:
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.tag
env:
# ARTIFACTS_SERVER: server/dist #TODO: fix here
ARTIFACTS_WEB: reearth-web_${{ needs.info.outputs.name }}.tar.gz
steps:
- name: Release nightly/rc
if: needs.info.outputs.name
uses: ncipollo/release-action@v1
with:
allowUpdates: true
artifactErrorsFailBuild : true
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.tag
uses: dawidd6/action-download-artifact@v2
with:
workflow: release.yml
name: changelog-${{ needs.info.outputs.tag }}
- name: Create GitHub release
if: needs.info.outputs.tag
uses: ncipollo/release-action@v1
with:
#TODO: サーバー側のartifactを修正
artifacts: ${{ env.ARTIFACTS_WEB }}
commit: ${{ github.sha }}
name: ${{ needs.info.outputs.tag }}
tag: ${{ needs.info.outputs.tag }}
bodyFile: CHANGELOG_latest.md
docker:
name: Build and push Docker image
runs-on: ubuntu-latest
Expand Down Expand Up @@ -113,6 +160,7 @@ jobs:
- name: Save imaged to artifact
uses: actions/upload-artifact@v2
with:
name: reearth-marketplace
name: '[ -n "$TAG" ] && echo reearth-marketplace_${{ steps.options.outputs.tags }} || echo reearth-marketplace_${{ steps.options.outputs.name }}'
path: reearth-marketplace.tar.gz
if-no-files-found: error
# TODO: invoke deploy test env if name == "nightly" with workflow_call event
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ on:
push:
branches:
- main
- release
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
ci_pre:
name: CI pre
runs-on: ubuntu-latest
if: github.event_name != 'push' || !startsWith(github.event.head_commit.message, 'v')
outputs:
web: ${{ steps.web.outputs.any_changed }}
server: ${{ steps.server.outputs.any_changed }}
Expand Down Expand Up @@ -75,6 +80,7 @@ jobs:
- name: Build extension
run: yarn build:ext
- name: Pack
if: ${{ github.ref == 'refs/heads/main' }}
run: mv dist reearth-marketplace-web && tar -zcvf reearth-marketplace-web.tar.gz reearth-marketplace-web
- uses: actions/upload-artifact@v3
if: ${{ github.ref == 'refs/heads/main' }}
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: release
on:
workflow_dispatch:
inputs:
version:
required: false
description: 'Next version ( NOTE: Switch the branch to "release"!)'
type: choice
default: minor
options:
- patch
- minor
- major

jobs:
release:
name: Release
runs-on: ubuntu-latest
if: github.ref == "refs/heads/release"
steps:
- name: git config
env:
GPT_USER: ${{ secrets.GPT_USER }}
run: |
git config --global user.name $GPT_USER
git config --global pull.rebase false
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GPT }}
- id: changelog
name: Generate CHANGELOG
uses: reearth/changelog-action@main
with:
version: ${{ github.event.inputs.version }}
repo: ${{ github.repository }}
latest: CHANGELOG_latest.md
- name: Upload latest CHANGELOG
uses: actions/upload-artifact@v3
with:
name: changelog-${{ steps.changelog.outputs.version }}
path: CHANGELOG_latest.md
- name: Commit & push to release
env:
TAG: ${{ steps.changelog.outputs.version }}
run: |
rm CHANGELOG_latest.md
git add CHANGELOG.md
git commit -am "$TAG"
git tag $TAG
git push --atomic origin release $TAG
- name: Commit & push to main
run: git switch main && git cherry-pick release && git push
26 changes: 26 additions & 0 deletions .github/workflows/stage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Stage
on:
workflow_dispatch:

jobs:
stage:
name: Stage
runs-on: ubuntu-latest
if: github.ref == "refs/heads/main"
steps:
- uses: git config
env:
GPT_USER: ${{ secrets.GPT_USER }}
run:
git config --global user.name $GPT_USER
git config --global pull.rebase false
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GPT }}
- name: Checkout release branch
run: git switch release || git switch -c release
- name: Merge main branch to release branch
run: git merge -X theirs main
- name: Git push
run: git push origin release

0 comments on commit c57a831

Please sign in to comment.