From ca8fdc2ffb2fded14d804192a09110f3d47126fb Mon Sep 17 00:00:00 2001 From: cansavvy Date: Tue, 20 Feb 2024 19:56:01 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=84=20Synced=20local=20'.github/workfl?= =?UTF-8?q?ows/'=20with=20remote=20'.github/workflows/'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit release-null --- .github/workflows/docker-test.yml | 95 +++++++++++++++++++++++++----- .github/workflows/pull_request.yml | 40 ++++--------- .github/workflows/render-site.yml | 5 +- 3 files changed, 95 insertions(+), 45 deletions(-) diff --git a/.github/workflows/docker-test.yml b/.github/workflows/docker-test.yml index afd658a..6d786f4 100644 --- a/.github/workflows/docker-test.yml +++ b/.github/workflows/docker-test.yml @@ -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/verify-changed-files@v8.8 + 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 "itcrtrainingnetwork@gmail.com" + 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 }} diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index af50f0a..e52060a 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -1,5 +1,5 @@ # Candace Savonen Dec 2021 - +# Updated April 2023 name: Pull Request on: @@ -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 "itcrtrainingnetwork@gmail.com" 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 }}" @@ -80,7 +65,7 @@ jobs: check_type: urls error_min: 0 gh_pat: secrets.GH_PAT - + render-preview: name: Render preview needs: yaml-check @@ -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 "itcrtrainingnetwork@gmail.com" git config --local user.name "jhudsl-robot" diff --git a/.github/workflows/render-site.yml b/.github/workflows/render-site.yml index 2d37fd1..41dc1ac 100644 --- a/.github/workflows/render-site.yml +++ b/.github/workflows/render-site.yml @@ -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"