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

add action to deploy assets from PR and delete them when the PR is closed #159

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
36 changes: 36 additions & 0 deletions .github/workflows/deploy-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
on:
pull_request_target:
types: [opened, edited, reopened, synchronize]
Comment on lines +1 to +3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if deploying automatically is a good idea. It could be unsafe to deploy PRs opened by external contributors, so deploying manually might be better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we could use workflow_dispatch instead to be on the safe side but we will need to run it manually each time the PR is updated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running manually seems fine to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might be able to trigger the action only on local PRs (so from branches on that repository) instead of PRs coming from forked repositories. How does that sound?


jobs:
build_css:
runs-on: ubuntu-latest
env:
source: public/dist/assets
destination: assets/website-2021/pr-${{ github.event.number }}/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we create a folder for all of them, rather than putting them directly under website-2021?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could use assets/website-2021-dev/ to avoid mixing prod and dev assets.

steps:
- name: Checkout source Git branch
uses: actions/checkout@v2
with:
ref: ${{github.event.pull_request.head.ref}}
persist-credentials: false

- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: '16'

- name: Install npm modules
run: npm install

- name: compile assets
run: npm run build

- name: Upload to cdn-dev.w3.org bucket
if: success()
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: 'us-east-1'
run:
aws s3 sync --no-progress ${{ env.source }} s3://cdn-dev.w3.org/${{ env.destination }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if we want to use cdn-dev or cdn. I think cdn-dev is restricted, and if so it may be difficult to show changes to external contributors.

19 changes: 19 additions & 0 deletions .github/workflows/pr-merged.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
on:
pull_request_target:
types:
- closed

jobs:
delete_assets:
runs-on: ubuntu-latest
env:
destination: assets/website-2021/pr-${{ github.event.number }}/
steps:
- name: Delete PR assets from the cdn-dev.w3.org bucket
if: success()
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: 'us-east-1'
run:
aws s3 rm --recursive s3://cdn-dev.w3.org/${{ env.destination }}