Skip to content

Commit

Permalink
feat: fetch Slack users for changelog actors (#16)
Browse files Browse the repository at this point in the history
This PR is part of our attempt to automate releases to staging. See the apify/apify-core#17156 for full context and next steps.

**It introduces following changes:**

- New **`github-changelog-authors`** output, that will be populated with a JSON string of changelog commit authors. This will only work if the changelog mode is either `pull_request_commits`, or `commits_compare`.
- New **`fetch-author-slack-ids`** input,  that when set to `true` will use Slack API to enhance each returned author with a matching Slack ID.

Fetching Slack IDs is for now placed outside the critical path: If it fails, the action will still succeed. This should allow for graceful degradation, but if it works reliably, we can change it.

**Sample output:** 

```
[{name:"Tobiáš Potoček",email:"tobias.potocek@apify.com",slackId:"U0xyz"}]
```

**The PR also  tries to improve the overall DX:**

- There is a new `watch` script that automatically builds the code.
- There is a new `test_action` workflow that executes the action when pushed to a PR.
- The `README.md` has been significantly extended.
  • Loading branch information
tobice authored Sep 4, 2024
1 parent 3fe58fd commit d4aff3c
Show file tree
Hide file tree
Showing 10 changed files with 351 additions and 74 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/test_action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Test the action

on:
pull_request:
branches: [ main ]

jobs:
test-release-pr-action:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '16' # Should correspond to .nvmrc

- name: Test Release pull request action
id: test-action
uses: ./
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
changelog-scopes: '{ "Action": ["action"] }'
base-branch: 'main'
create-release-pull-request: false
changelog-method: pull_request_commits
open-ai-token: ${{ secrets.OPEN_AI_TOKEN }}
release-name-method: 'tag'
slack-token: ${{ secrets.SLACK_BOT_USER_OAUTH_ACCESS_TOKEN }}
fetch-author-slack-ids: true

- name: Print changelog
run: echo "${{ steps.test-action.outputs.github-changelog }}"

- name: Print authors
run: echo "${{ steps.test-action.outputs.github-changelog-authors }}"
88 changes: 63 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@ This action is used to create release from commit history with

## Action input

| Name | Description | Example | Default | Required |
|-------------------------------------|--------------------------------------------------------------------------------|---------------------------------|----------------|----------|
| `github-token` | Github token with repository scope permissions | `${{ secrets.GITHUB_TOKEN }}` | NO DEFAULT | yes |
| `changelog-scopes` | Scopes, that will be show in changelog | `{"Worker": ["worker"]}` | NO DEFAULT | yes |
| `changelog-method` | Source from which to create changelog | `pull_request_description` | NO DEFAULT | yes |
| `slack-token` | Slack token with `chat.postMessage` permissions | `${{ secrets.SLACK_TOKEN }}` | NO DEFAULT | no |
| `slack-channel` | Slack channel ID | `XXXXXX` | NO DEFAULT | no |
| `release-name-method` | Whether to fetch release name from branch name or bump minor of last release | `branch` | `branch` | no |
| `create-release-pull-request` | Whether to create release pull request | `true` | `false` | no |
| `create-github-release ` | Whether to create github release | `true` | `false` | no |
| `base-branch` | Based branch where pull request will be created | `master` | `master` | no |
| `release-name-prefix` | Prepend prefix to release name (version) | `v` | `v` | no |
| `github-changelog-file-destination` | Where to store github changelog on filesystem | `github_changelog.md` | `changelog.md` | no |
| `open-ai-token` | Experimental feature see section [experimental feature](#experimental-feature).| `token` | NO_DEFAULT | no |
| Name | Description | Example | Default | Required |
|-------------------------------------|---------------------------------------------------------------------------------|-------------------------------|----------------|----------|
| `github-token` | Github token with repository scope permissions | `${{ secrets.GITHUB_TOKEN }}` | NO DEFAULT | yes |
| `changelog-scopes` | Scopes, that will be show in changelog | `{"Worker": ["worker"]}` | NO DEFAULT | yes |
| `changelog-method` | Source from which to create changelog | `pull_request_description` | NO DEFAULT | yes |
| `slack-token` | Slack token with sufficient scopes | `${{ secrets.SLACK_TOKEN }}` | NO DEFAULT | no |
| `slack-channel` | Slack channel ID | `XXXXXX` | NO DEFAULT | no |
| `release-name-method` | Whether to fetch release name from branch name or bump minor of last release | `branch` | `branch` | no |
| `create-release-pull-request` | Whether to create release pull request | `true` | `false` | no |
| `create-github-release ` | Whether to create github release | `true` | `false` | no |
| `base-branch` | Based branch where pull request will be created | `master` | `master` | no |
| `release-name-prefix` | Prepend prefix to release name (version) | `v` | `v` | no |
| `github-changelog-file-destination` | Where to store github changelog on filesystem | `github_changelog.md` | `changelog.md` | no |
| `open-ai-token` | Experimental feature see section [experimental feature](#experimental-feature). | `token` | NO_DEFAULT | no |
| `fetch-author-slack-ids` | Fetch Slack IDs of commit authors in the changelog | `true` | `false` | no |


### Input details

Expand All @@ -38,18 +40,20 @@ This action is used to create release from commit history with
* `pull_request_title` - Changelog will be taken from pull request's title (for `pull_request` trigger)
* `commits_compare` - Changelog will taken from comparison of commit messages between 2 branches

* both `slack-token` and `slack-channel` must be set to send message to slack
* both `slack-token` and `slack-channel` must be set to send message to Slack (plus the token needs `chat.postMessage` scope)
* `slack-token` must be set to fetch user Slack IDs (plus the token needs `users:read` and `users:read.email` scopes)
* `release-name-method` can be on of:
* `branch` - parse release name from branch name (i.e. `release/v1.2.3` -> `v.1.2.3`)
* `tag` - parse release name from latest and bump minor (i.e. `v1.2.3` -> `v.1.3.3`)
* `github-changelog-file-destination` controls the `github-changelog-file-destination` output

## Action output

| Name | Description | Example |
| ----------------------------------- | --------------------------- | ------------------- |
| `github-changelog` | Changelog content | `some cool feature` |
| `github-changelog-file-destination` | Changelog file destionation | `./changelog.md` |
| Name | Description | Example |
|-------------------------------------|-----------------------------------------|------------------------------------------------------------------------------|
| `github-changelog` | Changelog content | `some cool feature` |
| `github-changelog-file-destination` | Changelog file destination | `./changelog.md` |
| `github-changelog-authors` | Changelog commit authors as JSON string | `[{name:"Tobiáš Potoček",email:"tobias.potocek@apify.com",slackId:"U0xyz"}]` |

## Experimental feature

Expand Down Expand Up @@ -108,9 +112,43 @@ jobs:
## Contribution
1. Run `fnm use` (or `nvm`, or any other node manager you use)
2. Update code in `./src`
3. Run `npm i`
4. Run `npm run all`
5. Commit all changes including `./dist` folder with built code.
6. Publish a new version of action using new release (It needs to be done manually)
Developing Github Actions is tricky. You have essentially two options:
1. Use something like [`act`](https://github.com/nektos/act) to run actions and workflows locally.
2. Push changes to GitHub and let it run there.

For the second option, this repo contains a [test workflow](./.github/workflows/test_action.yaml) that will run the
`release-pr-action` on every PR push. As the action will run on your actual PR, `create-release-pull-request` is by
default `false` so that it doesn't override your PR title and description.

Note that you need to **manually build the code and commit the `dist` folder with the built code**.

### Local setup

1. Run `fnm use` (or `nvm`, or any other node manager you use).
2. Run `npm install`.
3. Run `npm run watch`.

### Development workflow

1. Update code in `./src`.
2. Wait for build to finish.
3. Commit all changes including `./dist` folder.
4. Push changes to GitHub.
5. Observe the action results.
6. Repeat.

Feel free to change the [test workflow](./.github/workflows/test_action.yaml) to suit your needs, but before merging
make sure it's configured with some reasonable defaults that will work for the next person making changes.

**Tip:** To avoid constantly switching to GitHub UI, you can use an IDE integration, such
as [GitHub Actions Manager](https://plugins.jetbrains.com/plugin/19347-github-actions-manager) for
WebStorm, or [GitHub Actions](https://marketplace.visualstudio.com/items?itemName=GitHub.vscode-github-actions) for
VSCode.

### Submit changes

1. If needed, run `npm run build` and commit and push any remaining changes.
2. Run `npm run test`.
3. Merge the PR.
4. Publish a new version of action using new release (It needs to be done manually).
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@ inputs:
open-ai-token:
required: false
description: 'Experimental feature: OpenAI token for improving changelog using text model'
fetch-author-slack-ids:
required: false
default: false
description: 'Fetch Slack IDs of commit authors in the changelog'
outputs:
github-changelog:
description: 'Changelog content in GihHub markdown'
github-changelog-file-destination:
description: 'Path to Github changelog file stored in file-system'
github-changelog-authors:
description: 'List of commit authors in the changelog as a JSON string. If fetch-author-slack-ids is set to true, the action will try to fetch a matching Slack ID for each author.'
runs:
using: 'node16'
main: 'dist/index.js'
Loading

0 comments on commit d4aff3c

Please sign in to comment.