Skip to content

Commit

Permalink
chore: add deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic100 committed Nov 5, 2024
1 parent 9d3e3a7 commit 666cebb
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 12 deletions.
17 changes: 6 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

- name: test summary
uses: phoenix-actions/test-reporting@v15
if: ${{ (success() || failure()) && github.repository == 'mistic100/Photo-Sphere-Viewer' }}
if: ${{ !cancelled() }}
with:
name: build
output-to: step-summary
Expand All @@ -50,24 +50,19 @@ jobs:
yarn ci:build
yarn ci:e2e
- name: test report
if: ${{ (success() || failure()) && github.repository == 'mistic100/Photo-Sphere-Viewer' && github.event_name != 'pull_request' }}
run: |
branch=$([ "${{ github.ref_name }}" == "main" ] && echo "" || echo "${{ github.ref_name }}")
node ./build/deploy-netlify.mjs --rootFolder=cypress/reports/html --exclude=.jsons --branch=$branch
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_REPORTS_SITE_ID }}

- name: test summary
uses: phoenix-actions/test-reporting@v15
if: ${{ (success() || failure()) && github.repository == 'mistic100/Photo-Sphere-Viewer' }}
if: ${{ !cancelled() }}
with:
name: e2e
output-to: step-summary
path: 'cypress/reports/html/.jsons/*.json'
reporter: mochawesome-json

- name: deploy report
uses: ./.github/workflows/shared/deploy-e2e-report
if: ${{ !cancelled() && github.repository == 'mistic100/Photo-Sphere-Viewer' && github.event_name != 'pull_request' }}

build-doc:
runs-on: ubuntu-latest
needs: build
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/shared/deploy-e2e-report/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: deploy-e2e-report

runs:
using: composite

steps:
- name: start deploy
uses: bobheadxi/deployments@v1
id: deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: cypress

- name: deploy
shell: bash
run: node ./build/deploy-netlify.mjs --rootFolder=cypress/reports/html --exclude=.jsons --branch=${{ github.ref_name }}
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_REPORTS_SITE_ID }}

- name: finish deploy
uses: bobheadxi/deployments@v1
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: success
env: ${{ steps.deployment.outputs.env }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
env_url: ${{ github.ref_name == 'main' && 'https://psv-cypress-reports.netlify.app' || format('https://{0}--psv-cypress-reports.netlify.app', github.ref_name) }}
26 changes: 25 additions & 1 deletion build/deploy-netlify.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import Queue from 'queue';
throw `Folder ${config.rootFolder} does not exist`;
}

if (config.branch === 'main') {
config.branch = null;
}

const files = await listFilesWithHashes(config.rootFolder, config.exclude, 'sha1');
// TODO zip functions
const functions = {};// await listFilesWithHashes(config.functionsFolder, null, 'sha256');
Expand All @@ -40,6 +44,10 @@ import Queue from 'queue';

await uploadFiles(config.rootFolder, files, deploy);
// await uploadFunctions(config.functionsFolder, functions, deploy);

if (!config.branch) {
await publishDeploy(deploy);
}
})();

/**
Expand Down Expand Up @@ -109,7 +117,7 @@ async function createDeploy(branch, files, functions) {
files,
functions: Object.entries(functions).reduce((res, [name, hash]) => ({
...res,
[name.replace('.zip')]: hash,
[name.replace('.zip', '')]: hash,
}), {}),
}),
});
Expand All @@ -121,6 +129,22 @@ async function createDeploy(branch, files, functions) {
return deploy;
}

/**
* Publish the deploy
*/
async function publishDeploy(deploy) {
const result = await fetch(`https://api.netlify.com/api/v1/sites/${process.env.NETLIFY_SITE_ID}/deploys/${deploy.id}/restore`, {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + process.env.NETLIFY_AUTH_TOKEN,
},
});

deploy = await result.json();

console.log(`Published deploy #${deploy.id} (${deploy.url}).`)
}

/**
* Upload new files to Netlify
*/
Expand Down
5 changes: 5 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { configureVisualRegression } from 'cypress-visual-regression';
// @ts-ignore
import cypressMochawesomeReporterPlugin from 'cypress-mochawesome-reporter/plugin';

const BRANCH_NAME = process.env.GITHUB_REF_NAME ?? 'dev';

export default defineConfig({
e2e: {
viewportWidth: 1280,
Expand Down Expand Up @@ -56,5 +58,8 @@ export default defineConfig({
// cypress-mochawesome-reporter
removeJsonsFolderAfterMerge: false,
cdn: true,
charts: true,
reportPageTitle: 'Photo Sphere Viewer',
reportTitle: `Photo Sphere Viewer (${BRANCH_NAME})`,
},
});

0 comments on commit 666cebb

Please sign in to comment.