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

Enhancement/automated pr wprocket and remove dist #12

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
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
Loading