I have two workflows one for ci and one for cd. The job is to deploy a static website to and s3 bucket. It should deploy the files within the artifact generated from the ci. I want to download the artifact and unzip to a directory inside my repository, this will then allow my cd to upload the files inside the www directory to s3 for static web hosting.
Here is the ci script
name: ci on: push: branches: [ "main" ] pull_request: branches: [ "main" ] jobs: build: runs-on: ubuntu-latest strategy: matrix: node-version: [12.x] steps: - uses: actions/checkout@v3 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 with: node-version: 12.8 cache: 'npm' - name: npm dependencies run: npm install - name: run run: npm run build --if-present - name: Archive production artifacts uses: actions/upload-artifact@v3 with: name: dist-without-markdown path: | www
Here is the cd script.
name: cd on: workflow_run: workflows: ["ci"] types: - completed jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@master - uses: jakejarvis/s3-sync-action@master with: args: --acl public-read --follow-symlinks --delete env: AWS_S3_BUCKET: udagram-frontend-sm AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} SOURCE_DIR: 'www' # optional: defaults to entire repository
You could use another action to download the artifact.
name: cd
on:
workflow_run:
workflows: ["ci"]
types:
- completed
jobs:
deploy:
runs-on: ubuntu-latest
needs: build # to ensure deploy run after build jobs
steps:
# the deploy step won't need checkout source code again.
# the download-artifact action can auto unzip artifact to the target folder.
- uses: actions/download-artifact@v3
with:
name: dist-without-markdown
path: www
- uses: jakejarvis/s3-sync-action@master
with:
args: --acl public-read --follow-symlinks --delete
env:
AWS_S3_BUCKET: udagram-frontend-sm
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SOURCE_DIR: 'www' # optional: defaults to entire repository
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.