Skip to content

Commit

Permalink
Upgrades to GHA workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
axisofentropy committed Feb 1, 2023
1 parent e1c13cf commit 4752c81
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 34 deletions.
35 changes: 20 additions & 15 deletions .github/workflows/build-images.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
name: Build Images

on:
push:
branches:
- main
- master
- staging
- qa
pull_request:
types: [opened,reopened,synchronize,closed]

Expand Down Expand Up @@ -146,17 +140,28 @@ jobs:
# Render simple template from environment variables.
envsubst < docker-compose.uffizzi.yml > docker-compose.rendered.yml
cat docker-compose.rendered.yml
- name: Hash Rendered Compose File
id: hash
run: echo "::set-output name=hash::$(md5sum docker-compose.rendered.yml | awk '{ print $1 }')"
- name: Cache Rendered Compose File
uses: actions/cache@v3
with:
path: docker-compose.rendered.yml
key: ${{ steps.hash.outputs.hash }}
- name: Upload Rendered Compose File as Artifact
uses: actions/upload-artifact@v3
with:
name: docker-compose
name: preview-spec
path: docker-compose.rendered.yml
retention-days: 2
- name: Upload PR Event as Artifact
uses: actions/upload-artifact@v3
with:
name: preview-spec
path: ${{ github.event_path }}
retention-days: 2

delete-preview:
name: Call for Preview Deletion
runs-on: ubuntu-latest
if: ${{ github.event.action == 'closed' }}
steps:
# If this PR is closing, we will not render a compose file nor pass it to the next workflow.
- name: Upload PR Event as Artifact
uses: actions/upload-artifact@v3
with:
name: preview-spec
path: ${{ github.event_path }}
retention-days: 2
56 changes: 37 additions & 19 deletions .github/workflows/uffizzi-preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ jobs:
cache-compose-file:
name: Cache Compose File
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
outputs:
compose-file-cache-key: ${{ steps.hash.outputs.hash }}
compose-file-cache-key: ${{ env.COMPOSE_FILE_HASH }}
pr-number: ${{ env.PR_NUMBER }}
steps:
- name: 'Download artifacts'
# Fetch output (zip archive) from the workflow run that triggered this workflow.
uses: actions/github-script@v6
with:
script: |
Expand All @@ -26,6 +29,9 @@ jobs:
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "docker-compose"
})[0];
if (matchArtifact === undefined) {
throw TypeError('Build Artifact not found!');
}
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
Expand All @@ -36,39 +42,51 @@ jobs:
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/docker-compose.zip`, Buffer.from(download.data));
- name: 'Unzip artifact'
run: unzip docker-compose.zip

- name: Read Event into ENV
run: |
echo 'EVENT_JSON<<EOF' >> $GITHUB_ENV
cat event.json >> $GITHUB_ENV
echo -e '\nEOF' >> $GITHUB_ENV
- name: Hash Rendered Compose File
id: hash
run: echo "::set-output name=hash::$(md5sum docker-compose.rendered.yml | awk '{ print $1 }')"
# If the previous workflow was triggered by a PR close event, we will not have a compose file artifact.
if: ${{ fromJSON(env.EVENT_JSON).action != 'closed' }}
run: echo "COMPOSE_FILE_HASH=$(md5sum docker-compose.rendered.yml | awk '{ print $1 }')" >> $GITHUB_ENV

- name: Cache Rendered Compose File
if: ${{ fromJSON(env.EVENT_JSON).action != 'closed' }}
uses: actions/cache@v3
with:
path: docker-compose.rendered.yml
key: ${{ steps.hash.outputs.hash }}
key: ${{ env.COMPOSE_FILE_HASH }}

- name: Read PR Number From Event Object
id: pr
run: echo "PR_NUMBER=${{ fromJSON(env.EVENT_JSON).number }}" >> $GITHUB_ENV

- name: DEBUG - Print Job Outputs
if: ${{ runner.debug }}
run: |
echo "PR number: ${{ env.PR_NUMBER }}"
echo "Compose file hash: ${{ env.COMPOSE_FILE_HASH }}"
cat event.json
deploy-uffizzi-preview:
name: Use Remote Workflow to Preview on Uffizzi
needs:
- cache-compose-file
uses: UffizziCloud/preview-action/.github/workflows/reusable.yaml@v2
#if: ${{ github.event.workflow_run.event.action != 'closed' }}
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: UffizziCloud/preview-action/.github/workflows/reusable.yaml@v2test
with:
# If this workflow was triggered by a PR close event, cache-key will be an empty string
# and this reusable workflow will delete the preview deployment.
compose-file-cache-key: ${{ needs.cache-compose-file.outputs.compose-file-cache-key }}
compose-file-cache-path: docker-compose.rendered.yml
server: https://app.uffizzi.com/
server: https://app.uffizzi.com
pr-number: ${{ needs.cache-compose-file.outputs.pr-number }}
permissions:
contents: read
pull-requests: write
id-token: write

# delete-uffizzi-preview:
# name: Use Remote Workflow to Delete an Existing Preview
# uses: UffizziCloud/preview-action/.github/workflows/reusable.yaml@v2
# if: ${{ github.event.workflow_run.event.action == 'closed' }}
# with:
# compose-file-cache-key: ''
# compose-file-cache-path: docker-compose.rendered.yml
# server: https://app.uffizzi.com/
# permissions:
# contents: read
# pull-requests: write
# id-token: write

0 comments on commit 4752c81

Please sign in to comment.