Skip to content

Deploy master

Deploy master #174

Workflow file for this run

name: Deploy master
on:
workflow_run:
workflows: ["Build & test"]
branches: [master]
types: [completed]
jobs:
deploy:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' && github.repository_owner == 'elan-ev' }}
steps:
- uses: actions/checkout@v3
- name: Prepare gh-pages branch
run: |
git fetch
if git checkout gh-pages; then
# Save CNAME and 404.html
tmpdir=$(mktemp -d)
cp CNAME 404.html $tmpdir || :
# Remove all previous files
git ls-files | while read -r f; do git rm -rf "$f"; done
# Restore 404.html and CNAME
cp $tmpdir/404.html $tmpdir/CNAME . || :
else
git checkout --orphan gh-pages
git ls-files | while read -r f; do rm -f "$f"; git rm --cached "$f"; done
fi
# Unfortunately we cannot use `actions/download-artifact` here since that
# only allows to download artifacts from the same run.
- name: Download artifacts from build workflow
uses: actions/github-script@v6
with:
script: |
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
const deployFiles = artifacts.data.artifacts
.filter(a => a.name == "prod-deployment-files")[0];
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: deployFiles.id,
archive_format: 'zip',
});
const fs = require('fs');
fs.writeFileSync('${{github.workspace}}/artifacts.zip', Buffer.from(download.data));
// The artifact is not needed anymore
github.rest.actions.deleteArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: deployFiles.id,
})
- name: extract artifacts
run: unzip artifacts.zip
- name: Prepare deployment files
run: |
mv .github/.deploy-settings.toml settings.toml
mv build/* .
rmdir build
- name: Commit and push
run: |
git add .
git config --global user.name 'GitHub Actions'
git config --global user.email '[email protected]'
git commit -m "Deploy ${{ github.event.workflow_run.head_sha }} ($(date))"
git push origin gh-pages