Skip to content

Merge pull request #56 from PostHog/future-plugins #53

Merge pull request #56 from PostHog/future-plugins

Merge pull request #56 from PostHog/future-plugins #53

Workflow file for this run

name: 'CD'
on:
push:
branches:
- main
- master
jobs:
check-package-version:
name: Check package version and detect an update
runs-on: ubuntu-20.04
outputs:
repo-version: ${{ steps.check-package-version.outputs.repo-version }}
published-version: ${{ steps.check-package-version.outputs.published-version }}
is-unpublished-version: ${{ steps.check-package-version.outputs.is-unpublished-version }}
steps:
- name: Checkout the repository
uses: actions/checkout@v2
- name: Check package version and detect an update
id: check-package-version
uses: PostHog/check-package-version@v1
release:
name: Publish release if new version
runs-on: ubuntu-20.04
needs: check-package-version
if: needs.check-package-version.outputs.is-unpublished-version == 'true'
env:
REPO_VERSION: ${{ needs.check-package-version.outputs.repo-version }}
PUBLISHED_VERSION: ${{ needs.check-package-version.outputs.published-version }}
steps:
- name: Checkout the repository
uses: actions/checkout@v2
with:
fetch-depth: 0
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}
- name: Set up Node 14
uses: actions/setup-node@v2
with:
node-version: 14
registry-url: https://registry.npmjs.org
- name: Install dependencies
run: yarn --frozen-lockfile
- name: Publish the package in the npm registry
run: npm publish --access public
env:
DATABASE_URL: 'postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres'
REDIS_URL: 'redis://localhost'
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.REPO_VERSION }}
release_name: ${{ env.REPO_VERSION }}
create-pull-requests:
name: Create main repo PR with new plugin-scaffold version
runs-on: ubuntu-20.04
needs: [check-package-version, release]
env:
REPO_VERSION: ${{ needs.check-package-version.outputs.repo-version }}
PUBLISHED_VERSION: ${{ needs.check-package-version.outputs.published-version }}
steps:
- name: Check out main repo
uses: actions/checkout@v2
with:
path: posthog
repository: PostHog/posthog
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}
- name: Check out plugin-scaffold repo
uses: actions/checkout@v2
with:
path: plugin-scaffold
fetch-depth: 0
- name: Install new plugin-scaffold version in main repo
id: yarn-upgrade-posthog
run: |
cd posthog/
OUTGOING_VERSION=$(jq '.dependencies["@posthog/plugin-scaffold"]' package.json -r)
echo "::set-output name=outgoing-version::$OUTGOING_VERSION"
for i in $(seq 1 $RETRY_TIMES); do
# Retry loop because of npm being _eventually_ consistent
if yarn upgrade @posthog/plugin-scaffold@${{ env.REPO_VERSION }}; then
break
else
[ $i -ne $RETRY_TIMES ] && sleep $RETRY_WAIT_SECONDS || false
fi
done
for i in $(seq 1 $RETRY_TIMES); do
if yarn --cwd plugin-server upgrade @posthog/plugin-scaffold@${{ env.REPO_VERSION }}; then
break
else
[ $i -ne $RETRY_TIMES ] && sleep $RETRY_WAIT_SECONDS || false
fi
done
env:
RETRY_TIMES: 20
RETRY_WAIT_SECONDS: 5
- name: Determine changelog
id: changelog
run: |
cd plugin-scaffold
PULL_REQUESTS=$(git log v${{ steps.yarn-upgrade.outputs.outgoing-version }}..v${{ env.REPO_VERSION }} --pretty=format:%s --grep='^.*\d*)$' --reverse | sed -e 's;(#;(PostHog/plugin-scaffold#;' -e 's/^/- /')
# Escape characters that are problematic for GitHub Actions set-output
PULL_REQUESTS="${PULL_REQUESTS//'%'/'%25'}"
PULL_REQUESTS="${PULL_REQUESTS//$'\n'/'%0A'}"
PULL_REQUESTS="${PULL_REQUESTS//$'\r'/'%0D'}"
echo "::set-output name=pull-requests::$PULL_REQUESTS"
- name: Create main repo pull request
id: main-repo-pr
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}
path: posthog
commit-message: 'chore(deps): Update plugin-scaffold to ${{ env.REPO_VERSION }}'
branch: plugin-scaffold-${{ env.REPO_VERSION }}
delete-branch: true
title: 'chore(deps): Update plugin-scaffold to ${{ env.REPO_VERSION }}'
labels: automerge
body: |
## Changes
plugin-scaffold version ${{ env.REPO_VERSION }} has been released. This updates PostHog to use it.
https://github.com/PostHog/plugin-scaffold/compare/v${{ steps.yarn-upgrade.outputs.outgoing-version }}...v${{ env.REPO_VERSION }}:
${{ steps.changelog.outputs.pull-requests }}
- name: Output pull request result
run: |
echo "PostHog pull request for plugin-scaffold version ${{ env.REPO_VERSION }} ready: ${{ steps.main-repo-pr.outputs.pull-request-url }}"