'Can't use the value of command in GitHub Actions
I tried merging dev branch to stage branch every 5 minutes, using GitHub Actions...
But it didn't work.
name: Auto merge dev2stage
on:
schedule:
- cron: "*/5 * * * *"
push:
branches:
- dev
jobs:
create-pullrequest-and-merge:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: dev
- name: dev2stage
run: |
PULL_REQUEST_VALUE=$(gh pr create -B stage -t dev2stage -b "")
gh pr merge $PULL_REQUEST_VALUE
$(gh pr create -B stage -t dev2stage -b "")
The command fails, if there were other pull request from the same base branch. Otherwise, it returns the value of the pull request URI.
I could not store the URI of the pull request. Why not does this script work?
Solution 1:[1]
Finally I solved this problem with this.
name: Auto merge dev2stage
on:
schedule:
- cron: "0 15 * * *"
jobs:
auto-merge-dev2stage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: dev
- name: ??????Create Pull Request dev2stage
id: create-pull-request
env:
GH_TOKEN: ${{ secrets.AUTO_DEP_TOKEN }}
run: |
PULL_REQUEST_URI=$(gh pr create -B stage -t ??????dev2stage -l 'auto merge' -b "")
echo "::set-output name=PULL_REQUEST_URI::$PULL_REQUEST_URI"
- name: ??????Merge Pull Request dev2stage
env:
GH_TOKEN: ${{ secrets.AUTO_DEP_TOKEN }}
run: |
gh pr merge ${{steps.create-pull-request.outputs.PULL_REQUEST_URI}} --merge
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ekusiadadus |
