Skip to content

Commit

Permalink
Setup ci
Browse files Browse the repository at this point in the history
  • Loading branch information
hadashiA committed Feb 3, 2024
1 parent 4030a56 commit b0a9ecf
Show file tree
Hide file tree
Showing 2 changed files with 175 additions and 0 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Release

on:
workflow_dispatch:
inputs:
tag:
description: "tag: git tag you want create. (sample 1.0.0)"
required: true
dry-run:
description: "dry-run: false = create release/nuget. true = never create release/nuget."
required: true
default: false
type: boolean

env:
GIT_TAG: ${{ github.event.inputs.tag }}

jobs:
update-version-number:
uses: ./.github/workflows/update-version-number.yaml
with:
tag: ${{ github.event.inputs.tag }}
dry-run: ${{ fromJson(github.event.inputs.dry-run) }}

# build-dotnet:
# needs: [update-version-number]
# runs-on: ubuntu-latest
# timeout-minutes: 10
# steps:
# - uses: actions/checkout@v3
# - uses: actions/setup-dotnet@v3
# with:
# dotnet-version: |
# 8.0.x
# - run: dotnet build -c Release
# - run: dotnet test -c Release --no-build
# - run: dotnet pack -c Release --no-build -o ./publish
# - uses: actions/upload-artifact@v3
# with:
# name: nuget
# path: ./publish
# - name: Publish
# if: github.event.inputs.dry-run == 'false'
# run: dotnet nuget push ./publish/*.nupkg -s 'https://api.nuget.org/v3/index.json' -k ${{secrets.NUGET_API_KEY}}

create-release:
if: github.event.inputs.dry-run == 'false'
# needs: [update-version-number, build-dotnet]
runs-on: ubuntu-latest
permissions:
contents: write
timeout-minutes: 10
steps:
# Create Releases
- uses: softprops/action-gh-release@v1
id: create_release
with:
tag_name: ${{ env.GIT_TAG }}
name: v${{ env.GIT_TAG }}
draft: true
prerelease: false
generate_release_notes: true
113 changes: 113 additions & 0 deletions .github/workflows/update-version-number.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Update Version Number

on:
workflow_dispatch:
inputs:
tag:
description: "git tag you want create. (sample 1.0.0)"
required: true
type: string
dry-run:
description: "true to simularate commit but not push change."
required: true
type: boolean
push-tag:
description: "true = push tag. false = no push tag."
required: false
type: boolean
default: true

workflow_call:
inputs:
tag:
description: "git tag you want create. (sample 1.0.0)"
required: true
type: string
dry-run:
description: "true to simularate commit but not push change."
required: true
type: boolean
push-tag:
description: "true = push tag. false = no push tag."
required: false
type: boolean
default: true
outputs:
sha:
description: "Git commit sha has changed."
value: ${{ jobs.update-packagejson.outputs.sha }}
branch-name:
description: Git branch name created.
value: ${{ jobs.update-packagejson.outputs.branch-name }}
is-branch-created:
description: Indicate is Git branch created or not.
value: ${{ jobs.update-packagejson.outputs.is-branch-created }}

jobs:
update-version-number:
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
sha: ${{ steps.commit.outputs.sha }}
branch-name: ${{ steps.configure.outputs.branch-name }}
is-branch-created: ${{ steps.configure.outputs.is-branch-created }}
steps:
- name: Configure Output variables
id: configure
run: |
echo "git-tag=${{ inputs.tag }}" | tee -a "$GITHUB_OUTPUT"
echo "dry-run=${{ inputs.dry-run }}" | tee -a "$GITHUB_OUTPUT"
echo "branch-name=test-release/${{ inputs.tag }}" | tee -a "$GITHUB_OUTPUT"
echo "is-branch-created=${{ inputs.dry-run }}" | tee -a "$GITHUB_OUTPUT"
- uses: actions/checkout@v4

- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'

- name: Update package.json ${{ steps.configure.outputs.git-tag }}
run: |
ruby -i -pe 'gsub(/"version"\s*:\s*"([\d\.]+)"/, %q{"version": "${{ steps.configure.outputs.git-tag }}"})' VitalRouter.Unity/Assets/VitalRouter/package.json
- name: Update Directory.Build.props ${{ steps.configure.outputs.git-tag }}
run: |
ruby -i -pe 'gsub(%r{(<PackageVersion>)[\d\.]+(</PackageVersion>)}, %q{\1${{ steps.configure.outputs.git-tag }}\2})' Directory.Build.props
- name: Update README.md ${{ steps.configure.outputs.git-tag }}
run: |
ruby -i -pe 'gsub(%r{(https://github.com/hadashiA/VitalRouter.git\?path=VitalRouter.Unity/Assets/VitalRouter#)[\d\.]+}, %q{\1${{ steps.configure.outputs.git-tag }}})' README.md
- name: Check update on git
id: check_update
run: git diff --exit-code || echo "changed=1" | tee -a "$GITHUB_OUTPUT"

- name: Commit files
id: commit
if: ${{ steps.check_update.outputs.changed == '1' }}
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -m "${{ steps.configure.outputs.git-tag }}" -a
echo "sha=$(git rev-parse HEAD)" | tee -a "$GITHUB_OUTPUT"
- name: Create Tag
if: ${{ steps.check_update.outputs.changed == '1' && inputs.push-tag }}
run: git tag ${{ steps.configure.outputs.git-tag }}

- name: Push changes
if: ${{ steps.configure.outputs.dry-run == 'false' && steps.check_update.outputs.changed == '1' }}
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
tags: ${{ inputs.push-tag }}

- name: Push changes (dry-run)
if: ${{ steps.configure.outputs.dry-run == 'true' && steps.check_update.outputs.changed == '1' }}
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: "refs/heads/${{ steps.configure.outputs.branch-name }}"
tags: false
force: true

0 comments on commit b0a9ecf

Please sign in to comment.