Skip to content

Commit

Permalink
upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
landsman committed Dec 14, 2021
1 parent 59f965b commit f3056f5
Show file tree
Hide file tree
Showing 30 changed files with 1,769 additions and 166 deletions.
120 changes: 120 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: build PR templates
on:
pull_request:
paths-ignore:
- '**.md'

jobs:
pull-request:
runs-on: ubuntu-latest
env:
RELEASE_VERSION: pr-${{ github.event.number }}
PROJECT_NAME: unicorn-mailing
GCP_BUCKET: ${{ secrets.PRODUCTION_GCP_BUCKET }}
GCP_SA_KEY: ${{ secrets.PRODUCTION_GCP_SA_KEY }}
GCP_URL_MAP_NAME: web-cdn-production
BUILD_URL: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
steps:

- name: 'Send working message to PR as comment'
uses: marocchino/sticky-pull-request-comment@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
recreate: true
message: |
⏳ Starting build, please wait ...
---
_You can watch progress on [build URL](${{ env.BUILD_URL }})_
# Environment setup
- name: 'Pull source code'
uses: actions/checkout@master

- name: 'Set Node.js'
uses: actions/setup-node@master
with:
node-version: 10.x

# Build
- name: 'Install dependencies'
run: npm install

- name: 'Build templates'
env:
STATUS: production
RELEASE_VERSION: ${{ env.RELEASE_VERSION }}
GCP_BUCKET: ${{ env.GCP_BUCKET }}
run: npm run build

# Put templates to zip
- name: 'Archive artifacts'
uses: actions/upload-artifact@v1
with:
name: templates-pull-request
path: build

- name: 'Google Cloud setup'
uses: google-github-actions/setup-gcloud@master
with:
version: '306.0.0'
project_id: unicorn-mailing
service_account_key: ${{ env.GCP_SA_KEY }}
export_default_credentials: true

- name: 'Build rsync to GCP bucket'
run: |
gsutil -q \
rsync -r -d -j html,png,css \
build/${{ env.RELEASE_VERSION }} gs://${{ env.GCP_BUCKET }}/${{ env.RELEASE_VERSION }}
- name: 'Invalidate cache in GCP bucket'
run: |
gcloud compute url-maps invalidate-cdn-cache ${{ env.GCP_URL_MAP_NAME }} \
--host ${{ env.GCP_BUCKET }} \
--path "/${{ env.RELEASE_VERSION }}/*"
- name: 'List bucket'
id: bucket
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
BUCKET_PATH: ${{ env.GCP_BUCKET }}/${{ env.RELEASE_VERSION }}
run: |
gsutil ls gs://${{ env.BUCKET_PATH }}/**.html | \
sed 's|gs:|https:|g' > list1.txt
while IFS= read -r line; \
do echo "- [$(echo $line | sed 's|https://${{ env.BUCKET_PATH }}/||g')]($line)" >> list2.txt; \
done < list1.txt
OUTPUT=$(cat list2.txt)
OUTPUT="${OUTPUT//'%'/'%25'}​"
OUTPUT="${OUTPUT//$'\n'/'%0A'}"
OUTPUT="${OUTPUT//$'\r'/'%0D'}"
echo "::set-output name=LIST_BUCKET::$OUTPUT"
- name: 'Send URL address to PR as comment'
uses: marocchino/sticky-pull-request-comment@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
recreate: true
message: |
👍 **Build done!**
Templates preview:
${{ steps.bucket.outputs.LIST_BUCKET }}
- name: 'The job has failed'
if: ${{ failure() }}
uses: marocchino/sticky-pull-request-comment@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
recreate: true
message: |
🔥 **Build failed**
---
_Please check logs on [build URL](${{ env.BUILD_URL }})_
72 changes: 72 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: release production templates

on:
release:
types: [published]

jobs:
release:
runs-on: ubuntu-latest
env:
ARTIFACT_FILE: template-release
GCP_BUCKET: ${{ secrets.PRODUCTION_GCP_BUCKET }}
GCP_BUCKET_PUBLIC_URL: ${{ secrets.GCP_BUCKET_PUBLIC_URL }}
GCP_SA_KEY: ${{ secrets.PRODUCTION_GCP_SA_KEY }}
steps:

# Environment setup
- name: Pull source code
uses: actions/checkout@master

- name: Set Node.js
uses: actions/setup-node@master
with:
node-version: 10.x

# Build templates
- name: Install dependencies
run: npm install

- name: Build templates
env:
STATUS: production
RELEASE_VERSION: ${{ github.event.release.tag_name }}
GCP_BUCKET: ${{ env.GCP_BUCKET }}
GCP_BUCKET_PUBLIC_URL: ${{ env.GCP_BUCKET_PUBLIC_URL }}
run: npm run build

# Zip them for Artifacts, Release Assets
- name: Zip it
run: |
cd build
zip -r -qq -D ../${{ env.ARTIFACT_FILE }}.zip .
cd ..
# Put templates to zip, add them to Action Artifacts
- name: Archive production artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ env.ARTIFACT_FILE }}
path: build

# Put templates to zip, add them to the Release Assets
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ${{ env.ARTIFACT_FILE }}.zip
asset_name: ${{ env.ARTIFACT_FILE }}.zip
asset_content_type: application/zip

# Upload Build to GCB
- name: Cloud Storage Uploader
id: uploaded-files
uses: google-github-actions/upload-cloud-storage@main
with:
credentials: ${{ env.GCP_SA_KEY }}
path: build/${{ github.event.release.tag_name }}
destination: ${{ env.GCP_BUCKET }}

5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
build/*
.idea
!build/.gitkeep
tmp/*
.env
.idea/
Loading

0 comments on commit f3056f5

Please sign in to comment.