Skip to content

Commit

Permalink
Merge pull request #5 from theorchard/dev
Browse files Browse the repository at this point in the history
[ci] Change to work within theorchard
  • Loading branch information
wilsonpage authored Nov 12, 2021
2 parents e368d64 + 550afec commit ba68cec
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 456 deletions.
14 changes: 14 additions & 0 deletions .github/actions/songwhip-events/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: 'songwhip-events dispatch action'
description: 'Trigger a songwhip-event'

inputs:
event:
description: 'Event object'
required: true
context:
description: 'Additional event context'
required: false

runs:
using: 'node12'
main: './index.js'
21 changes: 21 additions & 0 deletions .github/actions/songwhip-events/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { songwhipEventApi } = require('@theorchard/songwhip-events');

const inputs = {
event: process.env.INPUT_EVENT,
context: process.env.INPUT_CONTEXT,
};

(async () => {
const event = JSON.parse(
inputs.event || '{}'.replace(/\n/g, ' ').replace(/ +/g, ' ')
);

const context = JSON.parse(
inputs.context || '{}'.replace(/\n/g, ' ').replace(/ +/g, ' ')
);

await songwhipEventApi({
event,
context,
});
})();
21 changes: 21 additions & 0 deletions .github/workflows/onPullRequest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Pull request

on: pull_request

jobs:
deploy:
name: Deploy preview
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- run: ./scripts/create-npmrc ${{ secrets.NPM_GITHUB_TOKEN }}
- uses: bahmutov/npm-install@v1

- uses: amondnet/vercel-action@v20
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
github-token: ${{ github.token }}
vercel-org-id: team_1ufGuAGpA6R9b1EzxNxFVcNk
vercel-project-id: QmeyLmZ7W1GyfBPGrduX2oTQowiRiZiYWeUJMKcJRY8eFJ
scope: team_1ufGuAGpA6R9b1EzxNxFVcNk
51 changes: 51 additions & 0 deletions .github/workflows/onPushMaster.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Push master

on:
push:
branches:
- master

jobs:
deploy:
name: Deploy production
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- run: ./scripts/create-npmrc ${{ secrets.NPM_GITHUB_TOKEN }}
- uses: bahmutov/npm-install@v1

- uses: amondnet/vercel-action@v20
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
github-token: ${{ github.token }}
vercel-org-id: team_1ufGuAGpA6R9b1EzxNxFVcNk
vercel-project-id: QmeyLmZ7W1GyfBPGrduX2oTQowiRiZiYWeUJMKcJRY8eFJ
scope: team_1ufGuAGpA6R9b1EzxNxFVcNk
# --prod uses production domain (telegram.songwhip.com)
vercel-args: '--prod'

# this workflow is triggered by a 'push' event so the `event` payload doesn't
# contain information about the pull-request, this action fetches that data so that
# we can dispatch a useful message & url with the 'new-deployment' songwhip-event
- uses: actions-ecosystem/action-get-merged-pull-request@v1
id: get-merged-pull-request
with:
github_token: ${{ github.token }}

# a pull-request will be found when we merge into master from a pull-request (almost always)
- name: Dispatch 'new-deployment' event
uses: ./.github/actions/songwhip-events
if: ${{ steps.get-merged-pull-request.outputs.title != null }}
with:
event: '{ "type": "new-deployment", "serviceName": "songwhip-telegram", "message": "${{ steps.get-merged-pull-request.outputs.title }}", "url": "https://github.com/theorchard/songwhip-telegram/pull/${{ steps.get-merged-pull-request.outputs.number }}" }'
context: '{ "env": "production" }'

# if we didn't find a merged pr, use the head_commit, this will happen if ever we
# push to master instead of merging into master from a pull-request (emergency only?)
- name: Dispatch 'new-deployment' event
uses: ./.github/actions/songwhip-events
if: ${{ steps.get-merged-pull-request.outputs.title == null }}
with:
event: '{ "type": "new-deployment", "serviceName": "songwhip-telegram", "message": "${{ github.event.head_commit.message }}", "url": "https://github.com/theorchard/songwhip-telegram/commit/${{ github.event.head_commit.id }}" }'
context: '{ "env": "production" }'
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
.now
.npmrc
.vercel

node_modules
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"telegraf": "^3.30.1"
},
"devDependencies": {
"@theorchard/songwhip-events": "^2.3.3",
"@types/micro": "^7.3.3",
"babel-eslint": "^7.2.3",
"eslint": "^4.4.1",
Expand Down
12 changes: 12 additions & 0 deletions scripts/create-npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

AUTH_TOKEN=$1
DIR="$(cd "$(dirname "$0")" && pwd)"
NPMRC=$DIR/../.npmrc

# delete any existing .npmrc
rm $NPMRC 2> /dev/null

# create the .npmrc so that npm can see theorchard private packages
echo "@theorchard:registry=https://npm.pkg.github.com/" >> $NPMRC
echo "//npm.pkg.github.com/:_authToken=${AUTH_TOKEN}" >> $NPMRC
Loading

1 comment on commit ba68cec

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for songwhip-telegram ready!

✅ Preview
https://songwhip-telegram-cg4lfkc43-songwhip.vercel.app

Built with commit ba68cec.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.