[Prod] Build 98 of branch main by @microamp #98
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
name: Build and Release | |
run-name: ${{ github.event.inputs.publish == 'true' && '[Prod]' || '[Dev]' }} Build ${{ github.run_number }} of branch ${{ github.ref_name }} by @${{ github.actor }} | |
on: | |
workflow_dispatch: | |
inputs: | |
publish: | |
description: 'Create Production Release' | |
default: false | |
required: true | |
type: boolean | |
sandbox: | |
description: 'Deploy to Sandbox' | |
default: true | |
required: true | |
type: boolean | |
jobs: | |
# ----------------------------------------------------------------- | |
# BUILD / RELEASE | |
# ----------------------------------------------------------------- | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
outputs: | |
pkg_version: ${{ steps.buildvars.outputs.pkg_version }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Get Next Version | |
if: ${{ github.event.inputs.publish == 'true' }} | |
id: semver | |
uses: ietf-tools/semver-action@v1 | |
with: | |
token: ${{ github.token }} | |
branch: main | |
patchList: fix, bugfix, perf, refactor, test, tests, chore, ci, build | |
skipInvalidTags: true | |
- name: Create Draft Release | |
uses: ncipollo/[email protected] | |
if: ${{ github.event.inputs.publish == 'true' }} | |
with: | |
prerelease: true | |
draft: false | |
commit: ${{ github.sha }} | |
tag: ${{ steps.semver.outputs.next }} | |
name: ${{ steps.semver.outputs.next }} | |
body: '*pending*' | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set Build Variables | |
id: buildvars | |
run: | | |
if [[ $next ]]; then | |
echo "Using AUTO SEMVER mode: $next" | |
echo "pkg_version=$next" >> $GITHUB_OUTPUT | |
echo "image_tags=ghcr.io/${{ github.repository }}:$next,ghcr.io/${{ github.repository }}:latest" >> $GITHUB_OUTPUT | |
echo "::notice::Release $next created using branch $GITHUB_REF_NAME" | |
else | |
PKG_VERSION=v1.0.0-dev.$GITHUB_RUN_NUMBER | |
echo "Using TEST mode: $PKG_VERSION" | |
echo "pkg_version=$PKG_VERSION" >> $GITHUB_OUTPUT | |
echo "image_tags=ghcr.io/${{ github.repository }}:$PKG_VERSION" >> $GITHUB_OUTPUT | |
echo "::notice::Non-production build $PKG_VERSION created using branch $GITHUB_REF_NAME" | |
fi | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Docker Build & Push | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
file: docker/Dockerfile | |
target: app-sandbox | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: ${{ steps.buildvars.outputs.image_tags }} | |
- name: Set Helm Chart Version | |
env: | |
DEBIAN_FRONTEND: noninteractive | |
if: ${{ github.event.inputs.publish == 'true' }} | |
run: | | |
echo "Setting version ${{ steps.semver.outputs.nextStrict }}..." | |
sed -i -r -e "s|^version: .*$|version: '${{ steps.semver.outputs.nextStrict }}'|" helm/Chart.yaml | |
sed -i -r -e "s|^appVersion: ".*"$|appVersion: '${{ steps.semver.outputs.nextStrict }}'|" helm/Chart.yaml | |
- name: Package and Push Chart | |
if: ${{ github.event.inputs.publish == 'true' }} | |
run: | | |
helm plugin install https://github.com/chartmuseum/helm-push.git | |
helm repo add chartmuseum https://charts.ietf.org | |
helm cm-push --version="${{ steps.semver.outputs.nextStrict }}" --username="${{ secrets.HELM_REPO_USERNAME }}" --password="${{ secrets.HELM_REPO_PASSWORD }}" helm/ chartmuseum | |
helm repo remove chartmuseum | |
- name: Update CHANGELOG | |
id: changelog | |
uses: Requarks/changelog-action@v1 | |
if: ${{ github.event.inputs.publish == 'true' }} | |
with: | |
token: ${{ github.token }} | |
fromTag: ${{ steps.semver.outputs.next }} | |
toTag: ${{ steps.semver.outputs.current }} | |
writeToFile: false | |
- name: Create Release | |
uses: ncipollo/[email protected] | |
if: ${{ github.event.inputs.publish == 'true' }} | |
with: | |
makeLatest: true | |
allowUpdates: true | |
draft: false | |
tag: ${{ steps.semver.outputs.next }} | |
name: ${{ steps.semver.outputs.next }} | |
body: ${{ steps.changelog.outputs.changes }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Notify on Slack | |
if: ${{ always() }} | |
uses: slackapi/[email protected] | |
with: | |
channel-id: ${{ secrets.SLACK_GH_BUILDS_CHANNEL_ID }} | |
payload: | | |
{ | |
"text": "www - Build <https://github.com/ietf-tools/www/actions/runs/${{ github.run_id }}|${{ steps.buildvars.outputs.pkg_version }}> by ${{ github.triggering_actor }} completed" | |
} | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_GH_BOT }} | |
# ----------------------------------------------------------------- | |
# SANDBOX | |
# ----------------------------------------------------------------- | |
sandbox: | |
name: Deploy to Sandbox | |
if: ${{ github.event.inputs.sandbox == 'true' && github.event.inputs.publish == 'false' }} | |
needs: [build] | |
runs-on: [self-hosted, dev-server] | |
env: | |
PKG_VERSION: ${{needs.build.outputs.pkg_version}} | |
steps: | |
- name: Clear workspace folder from previous runs | |
# Fix because of bug in Checkout action: | |
# https://github.com/actions/checkout/issues/677 | |
run: | | |
rm -rf $GITHUB_WORKSPACE/.git | |
- uses: actions/checkout@v3 | |
- name: Download latest DB / media dump | |
env: | |
DEBIAN_FRONTEND: noninteractive | |
AWS_ACCESS_KEY_ID: ${{ secrets.DO_SPACES_DEV_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.DO_SPACES_DEV_ACCESS_KEY }} | |
run: | | |
aws s3 cp --quiet --endpoint-url=${{ secrets.DO_SPACES_DEV_ENDPOINT }} s3://wagtail/ietfa.torchbox.latest.gz ietfa.torchbox.latest.gz | |
aws s3 cp --quiet --endpoint-url=${{ secrets.DO_SPACES_DEV_ENDPOINT }} s3://wagtail/media.tgz media.tgz | |
- name: Deploy to containers | |
env: | |
DEBIAN_FRONTEND: noninteractive | |
run: | | |
echo "Install Deploy to Container CLI dependencies..." | |
cd dev/deploy-to-container | |
npm ci | |
cd ../.. | |
echo "Start Deploy..." | |
node ./dev/deploy-to-container/cli.js --branch ${{ github.ref_name }} --domain dev.ietf.org --appversion ${{ env.PKG_VERSION }} --commit ${{ github.sha }} --ghrunid ${{ github.run_id }} | |
- name: Cleanup old docker resources | |
env: | |
DEBIAN_FRONTEND: noninteractive | |
run: | | |
docker image prune -a -f |