Merge pull request #136 from RDFLib/jamie/release-workflow-fix #60
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: Deploy to GitHub Pages, push unstable Docker image to GHCR | |
on: | |
# Runs on push to main branch | |
push: | |
branches: | |
- main | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
env: | |
IMAGE_NAME: ghcr.io/rdflib/prez-ui | |
# Grants permissions for GITHUB_TOKEN | |
permissions: | |
contents: read | |
pages: write # to deploy to Pages | |
id-token: write # to verify the deployment originates from an appropriate source | |
packages: write # to push to GHCR package | |
jobs: | |
# Build & upload artifact for pages | |
build_pages: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Setup node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: latest | |
cache: npm | |
- name: Install and build | |
run: | | |
npm ci | |
CI=false npm run build | |
env: | |
VITE_SIDENAV: ${{ secrets.VITE_SIDENAV }} | |
VITE_ENABLED_PREZS: ${{ secrets.VITE_ENABLED_PREZS }} | |
VITE_API_BASE_URL: ${{ secrets.VITE_API_BASE_URL }} | |
VITE_MAP_SEARCH_PROPS_FC_LABEL: ${{ secrets.VITE_MAP_SEARCH_PROPS_FC_LABEL }} | |
VITE_MAP_SEARCH_PROPS_DS_LABEL: ${{ secrets.VITE_MAP_SEARCH_PROPS_DS_LABEL }} | |
GH_PAGES_DEMO: true | |
- name: Setup Pages | |
uses: actions/configure-pages@v2 | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v1 | |
with: | |
# Upload build directory | |
path: "dist" | |
# Deploy to github pages | |
deploy_pages: | |
# Add a dependency to the build job | |
needs: build_pages | |
# Deploy to the github-pages environment | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
# Specify runner + deployment step | |
runs-on: ubuntu-latest | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v1 | |
# build & push Docker image | |
docker: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v3 | |
with: | |
# Required by WyriHaximus/github-action-get-previous-tag | |
fetch-depth: 0 | |
- name: Get latest tag | |
id: latest-tag | |
uses: WyriHaximus/github-action-get-previous-tag@v1 | |
with: | |
fallback: "0.1.0" | |
- name: Tag starts with v | |
id: tag-starts-with-v | |
if: ${{ startsWith(steps.latest-tag.outputs.tag, 'v') }} | |
uses: mad9000/actions-find-and-replace-string@4 | |
with: | |
source: ${{ steps.latest-tag.outputs.tag }} | |
find: "v" | |
replace: "" | |
- name: Tag value | |
id: tag-value | |
uses: haya14busa/action-cond@v1 | |
with: | |
cond: ${{ startsWith(steps.latest-tag.outputs.tag, 'v') }} | |
if_true: ${{ steps.tag-starts-with-v.outputs.value }} | |
if_false: ${{ steps.latest-tag.outputs.tag }} | |
- name: Get next semver patch version | |
id: patch | |
uses: "WyriHaximus/github-action-next-semvers@v1" | |
with: | |
version: ${{ steps.tag-value.outputs.value }} | |
- name: Get git commits since last tag | |
id: commitscount | |
run: echo "value=$(git rev-list `git rev-list --tags --no-walk --max-count=1`..HEAD --count)" >> $GITHUB_OUTPUT | |
- name: Get git commit hash | |
id: commit-hash | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.IMAGE_NAME }} | |
tags: type=sha | |
- name: Rename git commit hash | |
id: hash | |
uses: mad9000/actions-find-and-replace-string@4 | |
with: | |
source: ${{ steps.commit-hash.outputs.version }} | |
find: "sha-" | |
replace: dev.${{ steps.commitscount.outputs.value }}. | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up and use Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v4 | |
with: | |
push: true | |
tags: | | |
${{ env.IMAGE_NAME }}:${{ steps.patch.outputs.patch }}-${{ steps.hash.outputs.value }} | |
${{ env.IMAGE_NAME }}:dev | |
# Set provenance to false due to issue documented here: https://github.com/docker/build-push-action/issues/778 | |
provenance: false | |
platforms: linux/amd64,linux/arm64 |