|
| 1 | +name: build |
| 2 | + |
| 3 | +env: |
| 4 | + GOPATH: /home/runner/work/gotest/gotest |
| 5 | + GO111MODULE: off |
| 6 | + REPO_PATH: src/gotest |
| 7 | + MACOS_GOPATH: /Users/runner/work/gotest/gotest |
| 8 | + GITHUB_TOKEN: ${{ github.token }} |
| 9 | + |
| 10 | +on: |
| 11 | + workflow_dispatch: |
| 12 | + inputs: |
| 13 | + id: |
| 14 | + description: 'Run ID' |
| 15 | + required: true |
| 16 | + runner: |
| 17 | + description: 'Github actions runner' |
| 18 | + required: false |
| 19 | + default: 'macos-latest' |
| 20 | + path: |
| 21 | + description: 'Directory where to run command' |
| 22 | + required: false |
| 23 | + default: '' |
| 24 | + pr: |
| 25 | + description: 'Pull request id' |
| 26 | + required: false |
| 27 | + default: '' |
| 28 | + go_version: |
| 29 | + description: 'Go version' |
| 30 | + required: false |
| 31 | + default: '1.17' |
| 32 | + command: |
| 33 | + description: 'Command to run' |
| 34 | + required: true |
| 35 | + default: '' |
| 36 | +jobs: |
| 37 | + build: |
| 38 | + runs-on: ${{ github.event.inputs.runner }} |
| 39 | + steps: |
| 40 | + - name: ${{ format('Run ID {0}', github.event.inputs.id) }} |
| 41 | + run: echo Run ID ${{github.event.inputs.id}} |
| 42 | + - name: Set environment for macos |
| 43 | + if: ${{ contains(github.event.inputs.runner, 'macos') }} |
| 44 | + run: | |
| 45 | + echo Changed GOPATH to ${{ env.MACOS_GOPATH }} |
| 46 | + echo "GOPATH="${{ env.MACOS_GOPATH }} >> $GITHUB_ENV |
| 47 | + - name: Set up Go |
| 48 | + uses: actions/setup-go@v2 |
| 49 | + with: |
| 50 | + go-version: ${{ github.event.inputs.go_version }} |
| 51 | + - name: Install dependencies |
| 52 | + run: go get -u github.com/magefile/mage |
| 53 | + - uses: actions/checkout@v2 |
| 54 | + with: |
| 55 | + fetch-depth: 0 |
| 56 | + ref: ${{ env.GITHUB_REF }} |
| 57 | + path: ${{ env.REPO_PATH }} |
| 58 | + - name: Checkout and merge PR |
| 59 | + if: ${{ github.event.inputs.pr }} |
| 60 | + run: | |
| 61 | + set -x |
| 62 | + cd ${{ env.GOPATH }}/${{ env.REPO_PATH }} |
| 63 | + git config --global user.email "user@example.com" |
| 64 | + git config --global user.name "user" |
| 65 | + git fetch origin pull/${{ github.event.inputs.pr }}/head:${{ github.event.inputs.id }} |
| 66 | + git checkout ${{ github.event.inputs.id }} |
| 67 | + git checkout $GITHUB_REF_NAME |
| 68 | + git merge --no-ff ${{ github.event.inputs.id }} |
| 69 | + - name: Run command |
| 70 | + run: | |
| 71 | + set -x |
| 72 | + cd ${{ env.GOPATH }}/${{ env.REPO_PATH }}/${{ github.event.inputs.path }} |
| 73 | + ${{ github.event.inputs.command }} |
0 commit comments