-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
431 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
{% raw %} | ||
name: PR Wayfinder preview | ||
|
||
on: | ||
workflow_run: | ||
workflows: ["Wayfinder validate manifests for deployment"] | ||
branches: [main] | ||
types: | ||
- completed | ||
# pull_request: | ||
# branches: | ||
# - main | ||
|
||
permissions: | ||
id-token: write | ||
contents: read | ||
pull-requests: write | ||
|
||
jobs: | ||
pr-preview-deploy: | ||
name: "Deploy PR #${{ github.event.pull_request.number }} to preview" | ||
runs-on: ubuntu-latest | ||
container: quay.io/${{ vars.WAYFINDER_QUAY_ORG }}/wftoolbox:${{ vars.WAYFINDER_VERSION }} | ||
needs: | ||
- update-pr | ||
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. | ||
permissions: | ||
contents: read | ||
packages: write | ||
attestations: write | ||
id-token: write | ||
|
||
steps: | ||
- name: Approve PR preview deployment | ||
uses: trstringer/manual-approval@v1 | ||
with: | ||
secret: ${{ github.TOKEN }} | ||
# approvers: user1,user2,org-team1 | ||
minimum-approvals: 1 | ||
timeout-minutes: 60 | ||
issue-title: "Deploying PR to preview environment" | ||
issue-body: "Please approve or deny the PR #${{ github.event.pull_request.number }} preview deployment" | ||
exclude-workflow-initiator-as-approver: false | ||
additional-approved-words: 'ok' | ||
additional-denied-words: 'nope' | ||
|
||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. | ||
- name: Log in to the Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. | ||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
|
||
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. | ||
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. | ||
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. | ||
- name: Build and push Docker image | ||
id: push | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: ./ | ||
push: true | ||
tags: ${{ env.IMAGE_NAME }}:${{ github.event.pull_request.number }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
|
||
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. | ||
- name: Generate artifact attestation | ||
uses: actions/attest-build-provenance@v1 | ||
with: | ||
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
subject-digest: ${{ steps.push.outputs.digest }} | ||
push-to-registry: true | ||
|
||
- name: Deploy to a preview environment | ||
id: deploy | ||
env: | ||
WAYFINDER_SERVER: ${{ vars.WAYFINDER_SERVER }} | ||
WAYFINDER_WORKSPACE: ${{ vars.WAYFINDER_WORKSPACE }} | ||
WAYFINDER_TOKEN: ${{ secrets.WAYFINDER_TOKEN_V2 }} | ||
DOCS_TAG: ${{ needs.build.outputs.tags }} | ||
run: | | ||
export PREVIEW_ENV="pr-${{ github.event.pull_request.number }}" | ||
{% endraw %} | ||
wf create appenv --app ${{ values.name }} --env ${PREVIEW_ENV} --cluster ${{ values.nonProdCluster }} --stage nonprod --wildcard-certs || true | ||
wf deploy component ${{ values.name }} ${PREVIEW_ENV} --component mysql --image ${DOCS_TAG} --wait-for-ready 3m | ||
wf deploy component ${{ values.name }} ${PREVIEW_ENV} --component app --image ${DOCS_TAG} --wait-for-ready 3m | ||
echo "PR_PREVIEW_URL=$(wf get appenv ${{ values.name }}-${PREVIEW_ENV} -o json | jq -r '.status.deployment.components[0].endpoint')" >> $GITHUB_OUTPUT | ||
{% raw %} | ||
|
||
- name: Add PR Comment | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
// 1. Retrieve existing bot comments for the PR | ||
const { data: comments } = await github.rest.issues.listComments({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: context.issue.number, | ||
}) | ||
const botComment = comments.find(comment => { | ||
return comment.user.type === 'Bot' && comment.body.includes('Deploy Preview') | ||
}) | ||
// 2. Get current time | ||
const currentDateTime = new Date(); | ||
// 3. Prepare format of the comment | ||
const output = `### Deploy Preview | ||
* 📖 <b>PR Preview Link:</b> https://${{ steps.deploy.outputs.PR_PREVIEW_URL }} | ||
This preview will be automatically deleted when the PR is closed. | ||
*<b>Generation Time:</b> ${currentDateTime}* | ||
*<b>Workflow Run Link:</b> ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}*`; | ||
// 4. If we have a comment, update it, otherwise create a new one | ||
if (botComment) { | ||
github.rest.issues.updateComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
comment_id: botComment.id, | ||
body: output | ||
}) | ||
} else { | ||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: output | ||
}) | ||
} | ||
{% endraw %} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# name: Wayfinder deploy manifests | ||
|
||
# on: | ||
# push: | ||
# branches: | ||
# - main | ||
# workflow_dispatch: | ||
|
||
# permissions: | ||
# contents: read | ||
|
||
# jobs: | ||
# wf-diff: | ||
# name: "Wayfinder Diff" | ||
# runs-on: ubuntu-latest | ||
# {% raw %} | ||
# container: quay.io/${{ vars.WAYFINDER_QUAY_ORG }}/wftoolbox:${{ vars.WAYFINDER_VERSION }} | ||
# outputs: | ||
# result: ${{ steps.diff.outcome }} | ||
# stdout: ${{ steps.diff.outputs.stdout }} | ||
# steps: | ||
# - name: Checkout Repository | ||
# uses: actions/checkout@v4 | ||
# - name: Wayfinder diff | ||
# id: diff | ||
# shell: bash | ||
# env: | ||
# WAYFINDER_SERVER: ${{ vars.WAYFINDER_SERVER }} | ||
# WAYFINDER_TOKEN: ${{ secrets.WAYFINDER_TOKEN }} | ||
# WAYFINDER_WORKSPACE: ${{ vars.WAYFINDER_WORKSPACE }} | ||
# run: | | ||
# set +e | ||
# wf diff -f ./wayfinder --owner ${{ vars.WAYFINDER_RESOURCE_OWNER }} --prune --prune-scope all 2>&1 | tee stdout.txt | ||
# diffExitCode=$? | ||
# EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) | ||
# echo "stdout<<$EOF" >> "$GITHUB_OUTPUT" | ||
# cat stdout.txt >> "$GITHUB_OUTPUT" | ||
# echo "$EOF" >> "$GITHUB_OUTPUT" | ||
# exit $diffExitCode | ||
# wf-apply: | ||
# name: "Wayfinder Apply" | ||
# needs: | ||
# - wf-diff | ||
# runs-on: ubuntu-latest | ||
# container: quay.io/${{ vars.WAYFINDER_QUAY_ORG }}/wftoolbox:${{ vars.WAYFINDER_VERSION }} | ||
# steps: | ||
# - name: Checkout Repository | ||
# uses: actions/checkout@v4 | ||
# - name: Wayfinder | ||
# env: | ||
# WAYFINDER_SERVER: ${{ vars.WAYFINDER_SERVER }} | ||
# WAYFINDER_TOKEN: ${{ secrets.WAYFINDER_TOKEN }} | ||
# WAYFINDER_WORKSPACE: ${{ vars.WAYFINDER_WORKSPACE }} | ||
# run: | | ||
# wf apply -f ./wayfinder --owner ${{ vars.WAYFINDER_RESOURCE_OWNER }} --prune --prune-scope all --wait-for-ready 5m --confirm | ||
# {% endraw %} | ||
# wf deploy app ${{ values.name }} prod |
Oops, something went wrong.