From da9956ccf33ae5b9bc713e7c428eb580cf32f50f Mon Sep 17 00:00:00 2001 From: icaparros-at-wiris Date: Thu, 19 Oct 2023 09:46:21 +0200 Subject: [PATCH 1/2] feat(wordpress): publish workflow to aws --- .github/workflows/publish-wordpress.yml | 99 +++++++++++++++++++++++++ .github/workflows/publish.yml | 47 ------------ packages/wordpress/VERSION | 1 - 3 files changed, 99 insertions(+), 48 deletions(-) delete mode 100644 packages/wordpress/VERSION diff --git a/.github/workflows/publish-wordpress.yml b/.github/workflows/publish-wordpress.yml index 0b85395bb..e1f712ff6 100644 --- a/.github/workflows/publish-wordpress.yml +++ b/.github/workflows/publish-wordpress.yml @@ -15,4 +15,103 @@ on: Type `publish_aws` to do publish to S3, any other value otherwise. required: false default: "" + version: + description: | + Version number, e.g.: "8.5.0" + required: false + default: "" + +# Array of jobs to run in this workflow +jobs: + publish-wordpres: + runs-on: ubuntu-latest + + if: github.event.inputs.publish_aws == 'publish_aws' + + steps: + - name: Checkout + uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + + # Install dependencies and create compiled files + - name: Build the JavaScript + run: | + yarn install + npx nx build wordpress + - name: Create Icons folder inside the build one + run: | + cp -a packages/wordpress/src/icons/ packages/wordpress/build/icons/ + echo ${{ github.event.inputs.version }} > VERSION + + # Create a zip file with the files needed to integrate + # Mathtype for WordPress + - name: Zip integration + uses: vimtor/action-zip@v1 + with: + files: packages/wordpress/build/ VERSION + dest: mathtype-tinymce-wordpress_${{ github.event.inputs.version }}.zip + - uses: vimtor/action-zip@v1 + with: + files: packages/wordpress/src/tiny_mce_wiris.php + dest: wordpress-wiris_${{ github.event.inputs.version }}.zip + + - name: Write the manifest of MathType for WordPress + run: | + cat << EOF > manifest.json + { + "items": [ + { + "tech": ["javascript"], + "editor": "tinymce5", + "version": "${{ github.event.inputs.version }}", + "date": "$(date -u +"%FT%T.000Z")", + "published": true, + "url": "https://downloads.wiris.com/integrations/wordpress/${{ github.event.inputs.version }}/mathtype-tinymce-wordpress_${{ github.event.inputs.version }}.zip", + "storename": "MT_WP" + }, + { + "tech": ["php"], + "editor": "tinymce5", + "version": "${{ github.event.inputs.version }}", + "date": "$(date -u +"%FT%T.000Z")", + "published": true, + "url": "https://downloads.wiris.com/integrations/wordpress/${{ github.event.inputs.version }}/wordpress-wiris_${{ github.event.inputs.version }}.zip", + "storename": "MT_WP_TINY" + } + ] + } + EOF + + - name: Upload artifacts to S3 rebost staging + env: + AWS_ACCESS_KEY_ID: ${{ secrets.REBOST_STG_AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.REBOST_STG_AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: ${{ secrets.STG_AWS_DEFAULT_REGION }} + AWS_DEFAULT_OUTPUT: json + S3_BUCKET: wiris-rebost-staging + S3_PATH: publish/integrations/wordpress + run: | + aws s3 cp --recursive --exclude "*" --include "*.zip" --exclude "**/*.zip" --include "manifest.json" . s3://${S3_BUCKET}/${S3_PATH}/${{ github.event.inputs.version }}/ + + - name: Upload artifacts to S3 downloads staging + env: + AWS_ACCESS_KEY_ID: ${{ secrets.DOWNLOADS_STG_AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.DOWNLOADS_STG_AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: ${{ secrets.STG_AWS_DEFAULT_REGION }} + AWS_DEFAULT_OUTPUT: json + S3_BUCKET: wiris-downloads-staging + S3_PATH: integrations/wordpress + run: | + aws s3 cp --recursive --exclude "*" --include "*.zip" --exclude "**/*.zip" . s3://${S3_BUCKET}/${S3_PATH}/${{ github.event.inputs.version }}/ + - name: Trigger Store staging links update + env: + AWS_ACCESS_KEY_ID: ${{ secrets.STORE_STG_AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.STORE_STG_AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: ${{ secrets.STG_AWS_DEFAULT_REGION }} + S3_BUCKET: wiris-store-staging-pipeline + run: | + mv manifest.json deploy + aws deploy push --application-name store-downloads --s3-location s3://${S3_BUCKET}/wordpress.zip --source deploy diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a46cac81c..387d2c47d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -48,50 +48,3 @@ jobs: # Call the script that interacts with the yarn CLI ./scripts/publish.mjs ${{ github.event.inputs.versions }} - - publish-wordpress: - runs-on: ubuntu-latest - - # If we want to publish the WordPress plugin, which is not needed on npm. - if: contains(github.event.inputs, 'wordpress') - - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 16 - - - name: Checkout - uses: actions/checkout@v2 - - # Install dependencies and create compiled files - - name: Build the JavaScript - run: | - yarn install - nx build wordpress - - name: Create Icons folder inside the build one - run: | - cp -a packages/wordpress/src/icons/ packages/wordpress/build/icons/ - - # Create a zip file with the files needed to integrate - # Mathtype for WordPress - - name: Zip integration - uses: vimtor/action-zip@v1 - with: - files: build/ VERSION - dest: "mathtype-tinymce-wordpress_${{ github.event.inputs.version }}.zip" - - uses: vimtor/action-zip@v1 - with: - files: wordpress-wiris-plugin/tiny_mce_wiris.php - dest: "wordpress-wiris_${{ github.event.inputs.version }}.zip" - - # Release WordPress plugin - - name: Release on GitHub - uses: marvinpinto/action-automatic-releases@latest - with: - repo_token: ${{ secrets.GITHUB_TOKEN }} - automatic_release_tag: "latest" - prerelease: true - title: "CI" - files: | - *.zip diff --git a/packages/wordpress/VERSION b/packages/wordpress/VERSION deleted file mode 100644 index a7e3b43bd..000000000 --- a/packages/wordpress/VERSION +++ /dev/null @@ -1 +0,0 @@ -8.3.0.1455 \ No newline at end of file From 0a1d59550aa36c7dd160027b4667def32a721cfd Mon Sep 17 00:00:00 2001 From: sgonzalez-at-wiris Date: Mon, 23 Oct 2023 18:39:34 +0200 Subject: [PATCH 2/2] feat: add deploy directory --- .github/workflows/publish-wordpress.yml | 4 +- deploy/appspec.yml | 12 +++++ deploy/postdeploy.sh | 68 +++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 deploy/appspec.yml create mode 100644 deploy/postdeploy.sh diff --git a/.github/workflows/publish-wordpress.yml b/.github/workflows/publish-wordpress.yml index e1f712ff6..733266681 100644 --- a/.github/workflows/publish-wordpress.yml +++ b/.github/workflows/publish-wordpress.yml @@ -69,7 +69,7 @@ jobs: "date": "$(date -u +"%FT%T.000Z")", "published": true, "url": "https://downloads.wiris.com/integrations/wordpress/${{ github.event.inputs.version }}/mathtype-tinymce-wordpress_${{ github.event.inputs.version }}.zip", - "storename": "MT_WP" + "storename": "MT_WP_TINY" }, { "tech": ["php"], @@ -78,7 +78,7 @@ jobs: "date": "$(date -u +"%FT%T.000Z")", "published": true, "url": "https://downloads.wiris.com/integrations/wordpress/${{ github.event.inputs.version }}/wordpress-wiris_${{ github.event.inputs.version }}.zip", - "storename": "MT_WP_TINY" + "storename": "MT_WP" } ] } diff --git a/deploy/appspec.yml b/deploy/appspec.yml new file mode 100644 index 000000000..19d5616bd --- /dev/null +++ b/deploy/appspec.yml @@ -0,0 +1,12 @@ +version: 0.0 +os: linux +files: + - source: manifest.json + destination: /tmp/ + +file_exists_behavior: OVERWRITE +hooks: + AfterInstall: + - location: postdeploy.sh + runas: root + timeout: 300 diff --git a/deploy/postdeploy.sh b/deploy/postdeploy.sh new file mode 100644 index 000000000..669557261 --- /dev/null +++ b/deploy/postdeploy.sh @@ -0,0 +1,68 @@ +#!/bin/bash +# Parses manifest.json + +## Valid JSON +if ! jq empty /tmp/manifest.json +then + echo "Invalid JSON. Exiting..." + exit 1 +fi + +NOW=$(date +%Y%m%d) +INPUT=/var/srv/store-manifests/wordpress.json +SQLTMP=/tmp/update.sql +OUTPUT=/var/log/store-dl-upgrades/wordpress.log # use /var/log and logrotate! +ITEMS=($(jq -c '.items[]' /tmp/manifest.json)) + +# Check if pkg version has changed +for i in ${!ITEMS[@]} +do + STORENAME=$(jq ".items[$i].storename" /tmp/manifest.json) + VERSION=$(jq ".items[$i].version" /tmp/manifest.json) + + if [ -z $(jq ".items[] | select(.storename == $STORENAME) | .storename" /var/srv/store-manifests/wordpress.json) ] || \ + [ ! -z $(jq ".items[] | select(.storename == $STORENAME) | select(.version!=$VERSION) | .version" /var/srv/store-manifests/wordpress.json) ] + then + UPDATE=true + fi +done + +if [ ! $UPDATE ] +then + echo "No Update needed" + exit 0 +fi + +# Copy manifest to store manifests directory +mkdir -p /var/srv/store-manifests && cp /tmp/manifest.json $INPUT +mkdir -p /var/log/store-dl-upgrades + +# Get all storenames and use them as index loop by object +objects=$(jq -r '.[] | .[] | .storename' $INPUT) + +for storetag in $objects ; do + echo "Now processing $storetag..." + object=$(jq -r '.items[] | select(.storename=="'$storetag'")' $INPUT) + + published=$(echo -n $object | jq -r '.published') + + if [[ $published == "false" ]] + then + echo "Skipping $storetag due to \"published == false\"" + continue + fi + + url=$(echo -n $object | jq -r '.url' | sed 's/downloads.wiris.com/downloads.wiris.kitchen/') + version=$(echo -n $object | jq -r '.version' | awk 'BEGIN {FS=OFS="."} {if (NF=="4") {NF--; print} else {print}}') + + echo "UPDATE downloads SET link='$url', timestamp=CURRENT_TIMESTAMP(), version='$version' WHERE name='$storetag';" >> $SQLTMP +done + +echo "Importing resulting SQL $SQLTMP into DB..." +mysql store < $SQLTMP + + +echo -e "===== $(date -Iseconds) =====" >> $OUTPUT +cat $SQLTMP >> $OUTPUT + +rm $SQLTMP