Skip to content

Commit

Permalink
🔄 Synced local '.github/workflows/' with remote '.github/workflows/'
Browse files Browse the repository at this point in the history
release-null
  • Loading branch information
cansavvy committed Feb 20, 2024
1 parent a8f7f8d commit ca8fdc2
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 45 deletions.
95 changes: 79 additions & 16 deletions .github/workflows/docker-test.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,90 @@
# Candace Savonen Apr 2021

name: Delete Preview
# Candace Savonen Apr 2022

name: Build Docker Image

on:
pull_request:
types: [closed]
workflow_dispatch:
inputs:
directory:
required: true
type: string
tag:
required: true
type: string
dockerhubpush:
description: 'Push to Dockerhub?'
required: false
default: 'false'
type: string
secrets:
GH_PAT:
required: true
DOCKERHUB_USERNAME:
required: false
DOCKERHUB_TOKEN:
required: false

jobs:
delete-preview:

build-docker:
name: Build Docker image
runs-on: ubuntu-latest

steps:
- name: checkout repo
uses: actions/checkout@v3

# This is because if a PR is closed before a render finishes it won't find it.
- name: Sleep for 5 minutes
run: sleep 300s
shell: bash
- name: Verify Dockerfiles changed?
uses: tj-actions/[email protected]
id: verify-changed-files
with:
files: |
${{ inputs.directory }}/Dockerfile
${{ inputs.directory }}/github_package_list.tsv
# Check out current repository
- name: checkout
uses: actions/checkout@v3
- name: Login as jhudsl-robot
run: |
git config --local user.email "[email protected]"
git config --local user.name "jhudsl-robot"
# Set up Docker build
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

# Setup layer cache
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Set up Docker Build
uses: docker/setup-buildx-action@v1

- name: Get token
run: echo ${{ secrets.GH_PAT }} > ${{ inputs.directory }}/git_token.txt

- name: Build Docker image
uses: docker/build-push-action@v2
with:
push: false
load: true
context: ${{ inputs.directory }}
file: ${{ inputs.directory }}/Dockerfile
tags: ${{ inputs.tag }}

# Login to Dockerhub
- name: Login to DockerHub
if: ${{ inputs.dockerhubpush != 'false' }}
uses: docker/login-action@v1
with:
fetch-depth: 0
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

# Delete the branch!
- name: Delete branch locally and remotely
run: git push origin --delete preview-${{ github.event.pull_request.number }} || echo "No branch to delete"
# Push the Docker image if set to true from a manual trigger
- name: Push Docker image if manual trigger set to true
if: ${{ inputs.dockerhubpush != 'false' }}
run: docker push ${{ inputs.tag }}
40 changes: 13 additions & 27 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Candace Savonen Dec 2021

# Updated April 2023
name: Pull Request

on:
Expand All @@ -23,36 +23,21 @@ jobs:
with:
files: config_automation.yml # Pass a space-separated list of configuration files. Rightmost files take precedence.

- name: Make branch if it doesn't exist
# Delete the branch if this has been run before
- name: Delete branch locally and remotely
run: git push origin --delete preview-${{ github.event.pull_request.number }} || echo "No branch to delete"

# Make the branch fresh
- name: Make the branch fresh
run: |
git config --local user.email "[email protected]"
git config --local user.name "jhudsl-robot"
branch_name='preview-${{ github.event.pull_request.number }}'
exists=$(git ls-remote https://${{ secrets.GH_PAT }}@github.com/$GITHUB_REPOSITORY $branch_name | wc -l | xargs)
if [[ $exists == 0 ]];then
echo branch doesnt exist
git checkout -b $branch_name || echo branch exists
git push --set-upstream origin $branch_name
else
echo branch does exist
fi
shell: bash

- name: Check if this is a private repository
id: public_repository
run: |
public=$(curl -Is https://github.com/${GITHUB_REPOSITORY} | head -1 | tr -dc '0-9')
if [ $public -eq 2200 ];then
public='true'
echo 'public repository'
else
public='false'
echo 'private repository'
fi
echo ::set-output name=public::$public
echo branch doesnt exist
git checkout -b $branch_name || echo branch exists
git push --set-upstream origin $branch_name
shell: bash

outputs:
public_repository: "${{ steps.public_repository.outputs.public }}"
toggle_spell_check: "${{ env.SPELL_CHECK }}"
Expand Down Expand Up @@ -80,7 +65,7 @@ jobs:
check_type: urls
error_min: 0
gh_pat: secrets.GH_PAT

render-preview:
name: Render preview
needs: yaml-check
Expand All @@ -98,6 +83,7 @@ jobs:
# Set up git checkout
- name: Set up git checkout
run: |
git config --system --add safe.directory $GITHUB_WORKSPACE
git config --local user.email "[email protected]"
git config --local user.name "jhudsl-robot"
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/render-site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ jobs:
- name: Commit rendered site files
run: |
git config --system --add safe.directory $GITHUB_WORKSPACE
git config --local user.email "itcrtrainingnetwork@gmail.com"
git config --local user.name "jhudsl-robot"
git config --local user.email "actions@github.com"
git config --local user.name "GitHub Actions"
git add --force *.html
git add --force subdir_html/*.html
git add --force site_libs/*
git commit -m 'Render site' || echo "No changes to commit"
git push origin main || echo "No changes to push"

0 comments on commit ca8fdc2

Please sign in to comment.