Skip to content

Commit

Permalink
Switch to GitHub Actions (deploy master to gh-pages, commits to DO sp…
Browse files Browse the repository at this point in the history
…aces) (#87)

* I'm not sure if this will work, time to test

* Try this

* This is it oohhhhhhh

* u wot github

* It'd just be deploy here

* That should be dist

* Test the action with a mock deployment

* Right branch would help

* Are quotes not a thing?

* No it does need quotes, echo the ref

* Try this

* Make it deployment ready

* This *should* work

* Hopefully this works

* Try this *I reset the bucket env var, this works locally*

* Set the ACL

* Lots of linting

* I don't know if this'll work

* Fixes

* Try this

* Fix the comment code

* Test using the GH token

* Fix auth header, Add new line

* Add content type

* Magic tidying fairy (∩ ͡° ͜ʖ ͡°)⊃━☆゚. * ・ 。゚,

* I'm not keeping this edit, I just want to test this

* Hmmmm that worked, lets test moving that space

* Try this (sorry for all the commits, I cannot recreate locally)

* try this
  • Loading branch information
IAmJSD authored and MattIPv4 committed Sep 13, 2019
1 parent c6306c2 commit 988f825
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 20 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: CI

on: push

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: Read .nvmrc
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
id: nvm

- name: Use Node.js (.nvmrc)
uses: actions/setup-node@v1
with:
node-version: "${{ steps.nvm.outputs.NVMRC }}"

- name: npm ci, test, and build
run: |
npm ci
npm test
npm run build
- name: Deploy master to GitHub Pages
if: github.ref == 'refs/heads/master'
uses: JamesIves/github-pages-deploy-action@2.0.0
env:
ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BASE_BRANCH: master
BRANCH: gh-pages
FOLDER: dist

- uses: chrislennon/action-aws-cli@v1.1

- name: Deploy commit to DigitalOcean Spaces
run: aws s3 sync ./dist s3://${{ secrets.SPACES_BUCKET }}/${{ github.sha }} --endpoint=https://${{ secrets.SPACES_REGION }}.digitaloceanspaces.com --acl public-read --content-encoding utf8
env:
AWS_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.SPACES_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.SPACES_REGION }}

- name: Leave a comment
run: node ./build/createGithubComment.js
env:
COMMIT_SHA: ${{ github.sha }}
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SPACES_REGION: ${{ secrets.SPACES_REGION }}
SPACES_BUCKET: ${{ secrets.SPACES_BUCKET }}
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

7 changes: 5 additions & 2 deletions build/buildTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ const index = async (file, out) => {
const post = posthtml(plugins)

// Process
const result = await post.process(source)
const html = (await post.process(source)).html

// Remove comments before HTML
const result = html.replace(/^(<!--.+?-->[\w\n]*)*/gms, '')

// Export
fs.writeFileSync(Path.join(__dirname, '..', out), result.html, { flag: 'w+' })
fs.writeFileSync(Path.join(__dirname, '..', out), result, { flag: 'w+' })
console.log(`...build successfully, saved to ${out}`)
}

Expand Down
59 changes: 59 additions & 0 deletions build/createGithubComment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
Copyright 2019 DigitalOcean
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

const fetch = require('node-fetch')
const path = require('path')
const { readdirSync } = require('fs')

const main = async () => {

const baseURL = `https://${process.env.SPACES_BUCKET}.${process.env.SPACES_REGION}.digitaloceanspaces.com/${process.env.COMMIT_SHA}`

const tools = readdirSync(path.join(__dirname, '..', 'dist'), { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name)
.map(name => `[${name}](${baseURL}/${name}/index.html)`)

const comment = `This commit has been deployed to DigitalOcean Spaces for easy reviewing.
| ${tools.join(' | ')} |
|${(new Array(tools.length).fill('---')).join('|')}|`

const res = await fetch(
`https://api.github.com/repos/do-community/dns-tool/commits/${process.env.COMMIT_SHA}/comments`,
{
method: 'POST',
body: JSON.stringify({
body: comment,
}),
headers: {
'Content-Type': 'application/json',
Accept: 'application/vnd.github.v3+json',
Authorization: `Basic ${Buffer.from(`github-actions:${process.env.GITHUB_ACCESS_TOKEN}`).toString('base64')}`,
}
},
).catch(async e => {
console.log(await e.json())
process.exit(1)
})

if (!res.ok) {
console.log(await res.json())
process.exit(1)
}
}

main()
12 changes: 9 additions & 3 deletions build/fetchTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const main = async () => {
let rawHTML = await res.text()

// Parse
const { document } = (new JSDOM(rawHTML)).window
const dom = new JSDOM(rawHTML)
const { document } = dom.window
const nav = document.querySelector('nav.do_nav')

// Nuke top log in button
Expand Down Expand Up @@ -58,8 +59,13 @@ const main = async () => {
}
})

// Inject charset
const charset = document.createElement('meta')
charset.setAttribute('charset', 'utf8')
document.head.insertBefore(charset, document.head.firstChild)

// Convert back to raw
rawHTML = document.documentElement.innerHTML
rawHTML = dom.serialize()

// Inject title block
rawHTML = rawHTML.replace(/<title>(.+?)<\/title>/, '<title><block name="title"></block>$1</title>')
Expand All @@ -72,7 +78,7 @@ const main = async () => {
'<block name="content"></block><div class="clearfix"></div>')

// Inject last fetch comment
rawHTML = rawHTML.replace('<head>', `<head><!-- Last fetch from www.digitalocean.com @ ${(new Date()).toISOString()} -->`)
rawHTML = rawHTML.replace('<head>', `<!-- Last fetch from www.digitalocean.com @ ${(new Date()).toISOString()} -->\n<head>`)

// Export
fs.writeFileSync(`${__dirname}/base.html`, rawHTML, { flag: 'w+' })
Expand Down
2 changes: 1 addition & 1 deletion src/spf-explainer/templates/spf.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ limitations under the License.
<div v-if="!loading">
<h5 class="title is-5">
<span v-for="(_, key) in links" :key="key" :ref="key">
<a @click="goToIndex(key)" @mouseover="markActive(key)">{{ key }}&nbsp;</a>
<a @click="goToIndex(key)" @mouseover="markActive(key)">{{ key }} </a>
</span>
</h5>
<div v-for="part in parts" :key="part[0]">
Expand Down

0 comments on commit 988f825

Please sign in to comment.