Clone And QA Deploy WordPress Post #95
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: Clone And QA Deploy WordPress Post | |
on: | |
workflow_dispatch: | |
inputs: | |
environment: | |
required: true | |
type: string | |
description: "The deployment environment (QA, PROD)" | |
default: "QA" | |
postID: | |
required: true | |
type: string | |
description: "The ID of the page to clone" | |
default: "25163" | |
jobs: | |
clone-post: | |
runs-on: ubuntu-latest | |
outputs: | |
should-run: ${{ steps.commit-changes.outputs.should-run }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '18' | |
- name: Install node dependencies | |
run: npm install | |
- name: Install python dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install requests beautifulsoup4 tqdm | |
- name: Run cloning html script | |
run: python wordpress-cloning-html-script.py ${{ inputs.environment }} ${{ inputs.postID }} ${{ secrets.WORDPRESS_USERNAME }} ${{ secrets.WORDPRESS_PASSWORD }} | |
- name: Run cloning css script | |
run: python wordpress-cloning-css-script.py ${{ inputs.environment }} ${{ secrets.WORDPRESS_USERNAME }} ${{ secrets.WORDPRESS_PASSWORD }} | |
- name: Run PurgeCSS | |
run: npm run purgecss | |
- name: Mix HTML and CSS in a single file | |
run: npm run grunt | |
- name: Run cloning css script | |
run: python wordpress-cloning-img-script.py ${{ inputs.environment }} ${{ secrets.WORDPRESS_USERNAME }} ${{ secrets.WORDPRESS_PASSWORD }} | |
- name: Configure git user | |
run: | | |
git config user.name 'GitHub Actions' | |
git config user.email '[email protected]' | |
- name: Commit and push changes | |
id: commit-changes | |
run: | | |
git add . | |
# Check if there are any changes | |
if git diff --staged --quiet; then | |
echo "No changes to commit." | |
echo "should-run=false" >> "$GITHUB_OUTPUT" | |
else | |
git commit -m "Cloned WordPress post ${{ github.event.inputs.postID }} for environment ${{ github.event.inputs.environment }}" | |
git push; | |
echo "should-run=true" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Debug output | |
run: | | |
echo "$Github_output file contents: " && cat "$GITHUB_OUTPUT" | |
echo steps.commit-changes.outputs.should-run: ${{ steps.commit-changes.outputs.should-run }} | |
env: | |
GITHUB_OUTPUT: ${{ github.workspace }}/output.txt | |
continue-on-error: true | |
shell: bash | |
release_new_version: | |
runs-on: ubuntu-latest | |
needs: clone-post | |
if: needs.clone-post.outputs.should-run == 'true' | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
fetch-tags: true | |
- name: Exit if no relevant changes | |
run: echo "Exiting because there are no changes in src" && exit 0 | |
- name: Get the current version tag | |
id: get_version | |
run: | | |
git checkout main | |
git pull | |
TAG=$(git tag --sort=-version:refname | head -n 1) | |
echo "Current version tag:" $TAG | |
echo "version=${TAG}" >> "$GITHUB_OUTPUT" | |
- name: Calculate new version | |
id: new_version | |
run: | | |
CURRENT_VERSION=${{ steps.get_version.outputs.version }} | |
MAJOR=$(echo $CURRENT_VERSION | cut -d'.' -f1) | |
MINOR=$(echo $CURRENT_VERSION | cut -d'.' -f2) | |
PATCH=$(echo $CURRENT_VERSION | cut -d'.' -f3) | |
NEW_PATCH=$((PATCH + 1)) | |
NEW_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}" | |
echo "New version: $NEW_VERSION" | |
echo "::set-output name=new_version::$NEW_VERSION" | |
- name: Create and push tag | |
run: | | |
NEW_TAG=${{ steps.new_version.outputs.new_version }} | |
git tag $NEW_TAG | |
git push origin $NEW_TAG | |
- name: Create GitHub release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.new_version.outputs.new_version }} | |
release_name: Release ${{ steps.new_version.outputs.new_version }} | |
draft: false | |
prerelease: false | |
upload_to_s3: | |
if: needs.clone-post.outputs.should-run == 'true' | |
needs: release_new_version | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Get recent changes | |
run: | | |
git pull | |
- name: Upload HTML to S3 | |
uses: reggionick/s3-deploy@v4 | |
with: | |
folder: dist | |
bucket: orcid-qa-public-page | |
bucket-region: 'us-east-1' | |
dist-id: 'E3AOMNP9201N9Z' | |
invalidation: / | |
delete-removed: true | |
no-cache: true | |
private: true | |
files-to-include: '{.*/**,**}' | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: 'us-east-1' | |
# clear_s3_bucket: | |
# needs: clone_post | |
# runs-on: ubuntu-latest | |
# steps: | |
# - name: Checkout code | |
# uses: actions/checkout@v3 | |
# - name: Configure AWS credentials | |
# uses: aws-actions/configure-aws-credentials@v1 | |
# with: | |
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
# aws-region: us-east-1 | |
# - name: Empty S3 Bucket | |
# run: | | |
# aws s3 rm s3://orcid-qa-public-page --recursive | |
# upload_to_s3: | |
# needs: clear_s3_bucket | |
# runs-on: ubuntu-latest | |
# steps: | |
# - name: Checkout repository | |
# uses: actions/checkout@v3 | |
# - name: Get recent changes | |
# run: | | |
# git pull | |
# - name: Upload HTML to S3 | |
# uses: jakejarvis/s3-sync-action@master | |
# with: | |
# args: --follow-symlinks --delete | |
# env: | |
# AWS_S3_BUCKET: orcid-qa-public-page | |
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
# AWS_REGION: 'us-east-1' | |
# SOURCE_DIR: 'dist' | |
# cloudfront_invalidation: | |
# needs: upload_to_s3 | |
# runs-on: ubuntu-latest | |
# steps: | |
# - name: Checkout code | |
# uses: actions/checkout@v2 | |
# - name: Configure AWS credentials | |
# uses: aws-actions/configure-aws-credentials@v1 | |
# with: | |
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
# aws-region: us-east-1 | |
# - name: Invalidate CloudFront cache | |
# run: | | |
# aws cloudfront create-invalidation --distribution-id E3AOMNP9201N9Z --paths "/*" |