Skip to content

Commit

Permalink
Post jobs to slack when PR is merged (#2)
Browse files Browse the repository at this point in the history
* Switch to on push; use parent hash for diff

* Update README for on push instead of opened PR

* Need to checkout depth 2 so parents are available
  • Loading branch information
jhkennedy authored Nov 3, 2021
1 parent 13a395a commit 68f712f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/post-jobs-slack.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
on:
pull_request:
push:
paths:
- 'example/jobs.yaml'
branches:
Expand All @@ -11,15 +11,18 @@ jobs:
name: Run Jobs Slack Poster
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 2

- id: updater
name: Job Updater
uses: ./
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
with:
with:
filename: "example/jobs.yaml"
key: "url"

- run: echo ${{ steps.updater.outputs.fields }}
name: Show New Jobs
shell: bash
shell: bash
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and a yaml file with a list of jobs (or other links):
url: https://my-job.org/12345
```

The action will inspect the file to determine lines that are newly added (compared to the main branch)
The action will inspect the file to determine lines that are newly added (compared to the parent commit)
for a field of interest (e.g., the "url" attribute in a list of jobs), extract this field, and then post to a Slack channel.

![img/example.png](img/example.png)
Expand Down Expand Up @@ -44,16 +44,14 @@ and put it in a safe place. We will want to keep this URL as a secret in our eve

## 2. Usage

Add an GitHub workflow file in .github/workflows to specify the following. Note that
the workflow below will do the check and update on the opening of a pull request.
Add an GitHub workflow file in `.github/workflows` to specify the following. Note that
the workflow below will do the check and update on any push to main (e.g., a merged pull request).

```yaml
on:
pull_request:
push:
paths:
- '_data/jobs.yml'
types:
- opened
branches:
- main

Expand All @@ -63,17 +61,19 @@ jobs:
name: Run Jobs Slack Poster
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 2

- id: updater
name: Job Updater
uses: rseng/jobs-updater@main
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
with:
with:
filename: "_data/jobs.yml"
key: "url"

- run: echo ${{ steps.updater.outputs.fields }}
name: Show New Jobs
shell: bash
```
6 changes: 1 addition & 5 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: 'Jobs Updater'
description: "The jobs updater will respond on some trigger, and them parse a jobs file for changes, posting a field of interest to slack."
inputs:
main:
description: main branch to compare to (defaults to main)
required: false
default: main
filename:
description: the filename for the jobs
required: true
Expand All @@ -28,8 +24,8 @@ runs:
id: jobs-updater
env:
INPUT_FILENAME: ${{ inputs.filename }}
INPUT_MAIN: ${{ inputs.main }}
INPUT_KEY: ${{ inputs.key }}
CURRENT_SHA: ${{ github.sha }}
ACTION_DIR: ${{ github.action_path }}
INPUT_REPO: ${{ github.repository }}
run: ${{ github.action_path }}/entrypoint.sh
Expand Down
3 changes: 2 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ if [[ ! -f "${INPUT_FILENAME}" ]]; then
fi

# Wget the comparison file
JOBFILE="https://raw.githubusercontent.com/${INPUT_REPO}/${INPUT_MAIN}/${INPUT_FILENAME}"
PARENT_SHA=$(git log --pretty=%P -n 1 ${CURRENT_SHA} | cut -d ' ' -f 1)
JOBFILE="https://raw.githubusercontent.com/${INPUT_REPO}/${PARENT_SHA}/${INPUT_FILENAME}"
TMP=$(mktemp -d)

BASENAME=$(basename ${INPUT_FILENAME})
Expand Down

0 comments on commit 68f712f

Please sign in to comment.