Compare commits
5 Commits
1.0.0
...
update/yam
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51b1329c52 | ||
|
|
9c31bb936c | ||
|
|
1e2916c992 | ||
|
|
820608e5d2 | ||
|
|
6251c0a094 |
47
README.md
47
README.md
@@ -5,31 +5,40 @@ whenever a branch with some prefix is pushed to. The idea is that you can
|
|||||||
set up some workflow that pushes content to branches of the repostory,
|
set up some workflow that pushes content to branches of the repostory,
|
||||||
and you would then want this push reviewed for merge to master.
|
and you would then want this push reviewed for merge to master.
|
||||||
|
|
||||||
Here is an example of what to put in your `.github/main.workflow` file to
|
Here is an example of what to put in your `.github/workflows/pull-request.yml` file to
|
||||||
trigger the action.
|
trigger the action.
|
||||||
|
|
||||||
```
|
```yaml
|
||||||
workflow "Create Pull Request" {
|
name: Pull Request on Branch Push
|
||||||
on = "push"
|
on:
|
||||||
resolves = "Create New Pull Request"
|
push:
|
||||||
}
|
branches-ignore:
|
||||||
|
- staging
|
||||||
action "Create New Pull Request" {
|
- launchpad
|
||||||
uses = "vsoch/pull-request-action@master"
|
- production
|
||||||
secrets = [
|
jobs:
|
||||||
"GITHUB_TOKEN"
|
auto-pull-request:
|
||||||
]
|
name: PullRequestAction
|
||||||
env = {
|
runs-on: ubuntu-latest
|
||||||
BRANCH_PREFIX = "update/"
|
steps:
|
||||||
PULL_REQUEST_BRANCH = "master"
|
- name: pull-request-action
|
||||||
}
|
uses: vsoch/pull-request-action@master
|
||||||
}
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
BRANCH_PREFIX: "update/"
|
||||||
|
PULL_REQUEST_BRANCH: "master"
|
||||||
```
|
```
|
||||||
|
|
||||||
Environment variables include:
|
Environment variables include:
|
||||||
|
|
||||||
- **BRANCH_PREFIX**: the prefix to filter to. If the branch doesn't start with the prefix, it will be ignored
|
- **BRANCH_PREFIX**: the prefix to filter to. If the branch doesn't start with the prefix, it will be ignored
|
||||||
- **PULL_REQUEST_BRANCH**: the branch to issue the pull request to. Defaults to master.
|
- **PULL_REQUEST_BRANCH**: the branch to issue the pull request to. Defaults to master.
|
||||||
|
- **PULL_REQUEST_BODY**: the body for the pull request (optional)
|
||||||
|
- **PULL_REQUEST_TITLE**: the title for the pull request (optional)
|
||||||
|
- **PULL_REQUEST_DRAFT**: should the pull request be a draft PR? (optional; unset defaults to `false`)
|
||||||
|
|
||||||
|
The `GITHUB_TOKEN` secret is required to interact and authenticate with the GitHub API to open
|
||||||
|
the pull request.
|
||||||
|
|
||||||
## Example use Case: Update Registry
|
## Example use Case: Update Registry
|
||||||
|
|
||||||
@@ -42,4 +51,6 @@ registry to update it.
|
|||||||
- the container collection metadata is pushed to a new branch on the registry repository, with namespace matching the GitHub repository, meaning that each GitHub repository always has a unique branch for its content.
|
- the container collection metadata is pushed to a new branch on the registry repository, with namespace matching the GitHub repository, meaning that each GitHub repository always has a unique branch for its content.
|
||||||
- pushing this branch that starts with the prefix (update/<namespace>) triggers the GitHub actions to open the pull request.
|
- pushing this branch that starts with the prefix (update/<namespace>) triggers the GitHub actions to open the pull request.
|
||||||
|
|
||||||
If the branch is already open for PR, it updates it.
|
If the branch is already open for PR, it updates it. Take a look at [this example](https://github.com/singularityhub/registry-org/pull/8)
|
||||||
|
for the pull request opened when we updated the previous GitHub syntax to the new yaml syntax. Although this
|
||||||
|
doesn't describe the workflow above, it works equivalently in terms of the triggers.
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ API_VERSION=v3
|
|||||||
BASE=https://api.github.com
|
BASE=https://api.github.com
|
||||||
AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}"
|
AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}"
|
||||||
HEADER="Accept: application/vnd.github.${API_VERSION}+json"
|
HEADER="Accept: application/vnd.github.${API_VERSION}+json"
|
||||||
HEADER="${HEADER}; application/vnd.github.antiope-preview+json"
|
HEADER="${HEADER}; application/vnd.github.antiope-preview+json; application/vnd.github.shadow-cat-preview+json"
|
||||||
|
|
||||||
# URLs
|
# URLs
|
||||||
REPO_URL="${BASE}/repos/${GITHUB_REPOSITORY}"
|
REPO_URL="${BASE}/repos/${GITHUB_REPOSITORY}"
|
||||||
@@ -44,12 +44,15 @@ check_events_json() {
|
|||||||
|
|
||||||
create_pull_request() {
|
create_pull_request() {
|
||||||
|
|
||||||
SOURCE=${1} # from this branch
|
SOURCE="${1}" # from this branch
|
||||||
TARGET=${2} # pull request TO this target
|
TARGET="${2}" # pull request TO this target
|
||||||
|
BODY="${3}" # this is the content of the message
|
||||||
|
TITLE="${4}" # pull request title
|
||||||
|
DRAFT="${5}" # if PRs are draft
|
||||||
|
|
||||||
# Check if the branch already has a pull request open
|
# Check if the branch already has a pull request open
|
||||||
|
|
||||||
DATA="{\"base\":\"${TARGET}\", \"head\":\"${SOURCE}\"}"
|
DATA="{\"base\":\"${TARGET}\", \"head\":\"${SOURCE}\", \"body\":\"${BODY}\"}"
|
||||||
RESPONSE=$(curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X GET --data "${DATA}" ${PULLS_URL})
|
RESPONSE=$(curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X GET --data "${DATA}" ${PULLS_URL})
|
||||||
PR=$(echo "${RESPONSE}" | jq --raw-output '.[] | .head.ref')
|
PR=$(echo "${RESPONSE}" | jq --raw-output '.[] | .head.ref')
|
||||||
echo "Response ref: ${PR}"
|
echo "Response ref: ${PR}"
|
||||||
@@ -60,11 +63,8 @@ create_pull_request() {
|
|||||||
|
|
||||||
# Option 2: Open a new pull request
|
# Option 2: Open a new pull request
|
||||||
else
|
else
|
||||||
TITLE="Update container ${SOURCE}"
|
|
||||||
BODY="This is an automated pull request to update the container collection ${SOURCE}"
|
|
||||||
|
|
||||||
# Post the pull request
|
# Post the pull request
|
||||||
DATA="{\"title\":\"${TITLE}\", \"base\":\"${TARGET}\", \"head\":\"${SOURCE}\"}"
|
DATA="{\"title\":\"${TITLE}\", \"base\":\"${TARGET}\", \"head\":\"${SOURCE}\", \"draft\":\"${DRAFT}\"}"
|
||||||
echo "curl --user ${GITHUB_ACTOR} -X POST --data ${DATA} ${PULLS_URL}"
|
echo "curl --user ${GITHUB_ACTOR} -X POST --data ${DATA} ${PULLS_URL}"
|
||||||
curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X POST --data "${DATA}" ${PULLS_URL}
|
curl -sSL -H "${AUTH_HEADER}" -H "${HEADER}" --user "${GITHUB_ACTOR}" -X POST --data "${DATA}" ${PULLS_URL}
|
||||||
echo $?
|
echo $?
|
||||||
@@ -91,6 +91,14 @@ main () {
|
|||||||
fi
|
fi
|
||||||
echo "Pull requests will go to ${PULL_REQUEST_BRANCH}"
|
echo "Pull requests will go to ${PULL_REQUEST_BRANCH}"
|
||||||
|
|
||||||
|
if [ -z "${PULL_REQUEST_DRAFT}" ]; then
|
||||||
|
echo "No explicit preference for draft PR: created PRs will be normal PRs."
|
||||||
|
PULL_REQUEST_DRAFT="false"
|
||||||
|
else
|
||||||
|
echo "Environment variable PULL_REQUEST_DRAFT set to a value: created PRs will be draft PRs."
|
||||||
|
PULL_REQUEST_DRAFT="true"
|
||||||
|
fi
|
||||||
|
|
||||||
# Get the name of the action that was triggered
|
# Get the name of the action that was triggered
|
||||||
BRANCH=$(jq --raw-output .ref "${GITHUB_EVENT_PATH}");
|
BRANCH=$(jq --raw-output .ref "${GITHUB_EVENT_PATH}");
|
||||||
BRANCH=$(echo "${BRANCH/refs\/heads\//}")
|
BRANCH=$(echo "${BRANCH/refs\/heads\//}")
|
||||||
@@ -106,7 +114,22 @@ main () {
|
|||||||
|
|
||||||
# Ensure we have a GitHub token
|
# Ensure we have a GitHub token
|
||||||
check_credentials
|
check_credentials
|
||||||
create_pull_request $BRANCH $PULL_REQUEST_BRANCH
|
|
||||||
|
# Pull request body (optional)
|
||||||
|
if [ -z "${PULL_REQUEST_BODY}" ]; then
|
||||||
|
echo "No pull request body is set, will use default."
|
||||||
|
PULL_REQUEST_BODY="This is an automated pull request to update the container collection ${BRANCH}"
|
||||||
|
echo "Pull request body is ${PULL_REQUEST_BODY}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Pull request title (optional)
|
||||||
|
if [ -z "${PULL_REQUEST_TITLE}" ]; then
|
||||||
|
echo "No pull request title is set, will use default."
|
||||||
|
PULL_REQUEST_TITLE="Update container ${BRANCH}"
|
||||||
|
echo "Pull request title is ${PULL_REQUEST_TITLE}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
create_pull_request $BRANCH $PULL_REQUEST_BRANCH $PULL_REQUEST_BODY $PULL_REQUEST_TITLE $PULL_REQUEST_DRAFT
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user