Skip to content

Commit

Permalink
Merge pull request #12 from wp-media/enhancement/automated-pr-wprocke…
Browse files Browse the repository at this point in the history
…t-and-remove-dist

Enhancement/automated pr wprocket and remove dist
  • Loading branch information
MathieuLamiot authored Aug 16, 2024
2 parents 14cdaf9 + 7332ce4 commit 4691b42
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 1,841 deletions.
102 changes: 97 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,110 @@ on:
release:
types: [published]
jobs:
build:
release-npmjs:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm publish --provenance --access public
- name: Install dependencies
run: npm ci
- name: Build project
run: npm run build
- name: Publish package
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

deploy-wprocket:
runs-on: ubuntu-latest
needs: release-npmjs
permissions:
contents: write
pull-requests: write

steps:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'

- name: Checkout WP Rocket repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_WORKFLOW_WPROCKET_ACCESS }}
repository: wp-media/wp-rocket
ref: develop
path: wp-rocket

- name: Checkout rocket-scripts
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_WORKFLOW_SELF_CHECKOUT }}
path: rocket-scripts

- name: Install dependencies
run: npm ci
working-directory: rocket-scripts
- name: Build project
run: npm run build
working-directory: rocket-scripts

- name: Get rocket-scripts version
id: get_version
run: |
VERSION=$(jq -r '.version' rocket-scripts/package.json)
echo "ROCKET_SCRIPTS_VERSION=${VERSION}" >> $GITHUB_ENV
- name: Checkout WP Rocket develop branch
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_WORKFLOW_WPROCKET_ACCESS }}
repository: wp-media/wp-rocket
ref: develop

- name: Update rocket-scripts files inside WP Rocket
run: |
cp rocket-scripts/dist/wpr-beacon.js wp-rocket/assets/js/wpr-beacon.js
cp rocket-scripts/dist/wpr-beacon.min.js wp-rocket/assets/js/wpr-beacon.min.js
cp rocket-scripts/dist/wpr-beacon.min.js.map wp-rocket/assets/js/wpr-beacon.min.js.map
- name: Move into wp-rocket folder
run: cd wp-rocket

- name: Update WP Rocket package.json
run: |
jq --arg version "$ROCKET_SCRIPTS_VERSION" \
'.devDependencies["wp-rocket-scripts"] = $version' \
package.json > package.json.tmp
mv package.json.tmp package.json
- name: Commit rocket-script update
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: update rocket-script
commit_user_name: WP Media GitHub Actions Bot

- name: create pull request
run: |
prs=$(gh pr list \
--repo "wp-media/wp-rocket" \
--head 'rocket-scripts' \
--base 'develop' \
--json title \
--jq 'length')
if ((prs > 0)); then
echo "skip=true" >> "$GITHUB_OUTPUT"
else
gh pr create -B develop -H 'rocket-scripts' --title 'Update rocket-script' --body 'Created by Github action'
fi
env:
GITHUB_TOKEN: ${{ secrets.GH_WORKFLOW_WPROCKET_ACCESS }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea
node_modules
/dist
package-lock.json
Loading

0 comments on commit 4691b42

Please sign in to comment.