From 4ae1c5e25cc3418c2f36cb2cab272b4a21fa9b31 Mon Sep 17 00:00:00 2001 From: vsoch Date: Tue, 17 Mar 2020 11:36:44 -0600 Subject: [PATCH] adding examples for push and release Signed-off-by: vsoch --- README.md | 4 ++- examples/push-example.yml | 18 ++++++++++++++ examples/release-example.yml | 48 ++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 examples/push-example.yml create mode 100644 examples/release-example.yml diff --git a/README.md b/README.md index ae50d05..2a973bf 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,9 @@ the pull request. The example is [deployed here](https://github.com/vsoch/pull-r ## Examples -Let's say that we are opening a pull request on the [publish]() event. This would mean +Example workflows are provided in [examples](examples), and please contribute any +examples that you might have to help other users! We will walk through a basic +example here for a niche case. Let's say that we are opening a pull request on the release event. This would mean that the payload's branch variable would be null. We would need to define `PULL_REQUEST_FROM`. How would we do that? We can [set environment variables](https://help.github.com/en/actions/reference/development-tools-for-github-actions#set-an-environment-variable-set-env) for next steps. Here is an example: diff --git a/examples/push-example.yml b/examples/push-example.yml new file mode 100644 index 0000000..678c3ae --- /dev/null +++ b/examples/push-example.yml @@ -0,0 +1,18 @@ +name: Pull Request on Branch Push +on: + push: + branches-ignore: + - staging + - launchpad + - production +jobs: + auto-pull-request: + name: PullRequestAction + runs-on: ubuntu-latest + steps: + - name: pull-request-action + uses: vsoch/pull-request-action@add/support-null-branch + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BRANCH_PREFIX: "update/" + PULL_REQUEST_BRANCH: "master" diff --git a/examples/release-example.yml b/examples/release-example.yml new file mode 100644 index 0000000..3e9c380 --- /dev/null +++ b/examples/release-example.yml @@ -0,0 +1,48 @@ +on: + release: + types: + - published + +jobs: + persist-new-suite-yml: + name: Commit Suite Release YML + runs-on: ubuntu-latest + + steps: + # Likely other steps go here + - name: Set BRANCH_NAME + run: | + tag_name=${{github.event.release.tag_name}} + echo "Tag: $tag_name" + + version=$(echo "$tag_name" | sed 's/^v//') + echo "Version: $version" + + echo "::set-output name=suite_version::${version}" + echo "::set-output name=suite_update_branch::suite_${version}" + id: data + + - name: Permanently save the new suite release + run: | + mkdir -p releases + + new_suite_version_yml="releases/suite_${{ steps.data.outputs.suite_version }}.yml" + echo "Suite target file: $new_suite_version_yml" + + cp suite.yml "${new_suite_version_yml}" + + git add "${new_suite_version_yml}" + git commit -m "Suite v${{ steps.data.outputs.suite_version }} auto-commit of new release files" + + - name: Push files + run: | + git push --force "https://${{ github.actor }}:${{secrets.GITHUB_TOKEN}}@github.com/${{ github.repository }}.git" "HEAD:${{ steps.data.outputs.suite_update_branch }}" + + - name: Open a PR to the default branch + uses: vsoch/pull-request-action@1.0.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PULL_REQUEST_FROM_BRANCH: "${{ steps.data.outputs.suite_update_branch }}" + PULL_REQUEST_BRANCH: master + PULL_REQUEST_TITLE: "Action: Update suite release file for v${{ steps.data.outputs.suite_version }}" + PULL_REQUEST_BODY: "Auto-generated PR!"