Skip to content

Publish Application Image #20

Publish Application Image

Publish Application Image #20

name: "Publish Application Image"
on:
push:
branches:
- app-image
- fake-image
paths-ignore:
- '**.md'
- '**.txt'
- '.**ignore'
- 'docs/**'
- '**package*.json'
workflow_dispatch:
inputs:
build_secret:
type: string
description: Build secret
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
timeout-minutes: 20
steps:
- name: Check secret
if: github.event_name == 'workflow_dispatch'
run: |
if [ "${{ github.event.inputs.build_secret }}" != "${{ secrets.BUILD_SECRET }}" ]; then
echo "Wrong build secret."
exit 1
fi
- name: Check user permission
if: github.event_name == 'workflow_dispatch'
id: check
uses: scherermichael-oss/action-has-permission@master
with:
required-permission: write
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Exit if user doesn't have write permission
if: github.event_name == 'workflow_dispatch'
run: |
if [ "${{ steps.check.outputs.has-permission }}" = "false" ]; then
echo "Only users with write permission are allowed to execute this workflow."
exit 1
fi
- uses: actions/checkout@v3
with:
token: ${{ secrets.PAT }}
- name: Fetch All Tags
run: git fetch --all --tags
# Setup .npmrc file to publish to GitHub Packages
- uses: actions/setup-node@v3
with:
cache: 'npm'
node-version: '16'
registry-url: 'https://registry.npmjs.org'
scope: '@sjcrh'
- name: Login to GitHub Container Registry
run: |
echo $CR_PAT | docker login ghcr.io -u stjude --password-stdin
env:
CR_PAT: ${{ secrets.PAT }}
- name: Build and Publish Docker Images
run: |
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
MODE="-w"
if [[ "$BRANCH" != "app-image" && "$BRANCH" != "release-chain" && "$BRANCH" != "master" && ${{ github.event_name }} != "workflow_dispatch" ]]; then
MODE=""
fi
cd container
npm install glob
./release.sh "$MODE"
if [[ "$MODE" == "-w" ]]; then
echo "merging to master"
git fetch --depth=10 origin master:master
# TODO: fix the following error on CI
# fatal: refusing to fetch into branch 'refs/heads/master' checked out at '/home/runner/work/proteinpaint/proteinpaint'
git switch master
git merge $BRANCH
git push
fi