Ensured branch slug is generated before building project on preview env deployment

This commit is contained in:
Alejandro Celaya 2021-05-09 13:53:36 +02:00
parent 9a245fbf13
commit f74270a767
2 changed files with 19 additions and 6 deletions

View file

@ -9,6 +9,7 @@ on:
jobs:
deploy:
runs-on: ubuntu-20.04
continue-on-error: true
steps:
- name: Checkout code
uses: actions/checkout@v2
@ -16,15 +17,14 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: 14.15
- name: Build
run: |
npm ci && \
npm install json && \
node_modules/.bin/json -I -f package.json -e "this.homepage=\"/shlink-web-client/${{ steps.generate_slug.outputs.slug }}\"" && \
npm run build
- name: Generate slug
id: generate_slug
run: echo "##[set-output name=slug;]$(echo ${GITHUB_REF#refs/heads/} | sed -r 's/[~\^]+//g' | sed -r 's/[^a-zA-Z0-9]+/-/g' | sed -r 's/^-+\|-+$//g' | tr A-Z a-z)"
- name: Build
run: |
npm ci && \
node ./scripts/set-homepage.js /shlink-web-client/${{ steps.generate_slug.outputs.slug }} && \
npm run build
- name: Deploy
uses: JamesIves/github-pages-deploy-action@4.1.1
with:

13
scripts/set-homepage.js Normal file
View file

@ -0,0 +1,13 @@
const argv = process.argv.slice(2);
const [ homepage ] = argv;
if (!homepage) {
throw new Error('Homepage has to be provided as the first arg for this script');
}
const packageJsonPath = `${__dirname}/../package.json`;
const packageJson = require(packageJsonPath);
const fs = require('fs');
packageJson.homepage = homepage;
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));