Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade #19

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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