Build and Deploy #13
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy | |
on: | |
# Runs on pushes targeting the default branch | |
push: | |
branches: ["master"] | |
release: | |
types: [published] | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
permissions: | |
contents: write | |
pages: write | |
id-token: write | |
packages: write | |
jobs: | |
# deploy docker to github registry | |
deployDocker: | |
if: github.event_name == 'release' | |
runs-on: ubuntu-latest | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Login to GitHub Packages | |
uses: docker/login-action@v1 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
# deploy static | |
deployStatic: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Build | |
run: | | |
bash build.sh | |
# Deploy to GitHub action artifacts | |
- name: Upload artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: anser-static-snapshot | |
path: "./dist/" | |
# Deploy to GitHub Releases | |
- name: Compress dist | |
if: github.event_name == 'release' | |
run: | | |
cd dist | |
zip -r ../anser-static-deploy.zip . | |
cd .. | |
- name: Deploy to release branch | |
if: github.event_name == 'release' | |
run: | | |
# Commit the changes | |
git config --global user.name "Github Actions" | |
git config --global user.email "[email protected]" | |
git clone --single-branch --branch "releases" [email protected]:${{ github.repository }} releases | |
cd releases | |
mkdir -p ${{ github.ref_name }} | |
cp ../dist/lib/liquidwallet.lib.js ${{ github.ref_name }} | |
git add . | |
git commit -m "update ${{ github.ref_name }}" | |
git push origin releases | |
- name: Deploy to GitHub Releases | |
if: github.event_name == 'release' | |
run: | | |
set -e | |
echo "${GITHUB_EVENT_PATH}" | |
cat ${GITHUB_EVENT_PATH} | |
releaseId=$(jq --raw-output '.release.id' ${GITHUB_EVENT_PATH}) | |
echo "Upload to release $releaseId" | |
filename="./anser-static-deploy.zip" | |
url="https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/$releaseId/assets?name=$(basename $filename)" | |
echo "Upload to $url" | |
curl -L \ | |
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Content-Type: application/zip" \ | |
--data-binary @"$filename" \ | |
"$url" | |
filename="./dist/lib/liquidwallet.lib.js" | |
url="https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/$releaseId/assets?name=$(basename $filename)" | |
echo "Upload to $url" | |
curl -L \ | |
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Content-Type: application/javascript" \ | |
--data-binary @"$filename" \ | |
"$url" | |
# deploy gh pages | |
deployPages: | |
if: github.event_name == 'release' | |
concurrency: ci-${{ github.ref }} | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup Pages | |
uses: actions/configure-pages@v4 | |
- name: Build | |
run: | | |
bash build.sh | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: "./dist/" | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 |