From 0870d785cb2c7823d23ca3ac910013afb98e7fc1 Mon Sep 17 00:00:00 2001 From: Andrew Morris Date: Mon, 3 Apr 2023 10:46:15 +1000 Subject: [PATCH] Simplify actions --- .github/actions/rust-cache/action.yaml | 16 ----- .github/workflows/test-and-deploy.yaml | 69 +++++++++++++++++++ .../workflows/{cargo-test.yaml => test.yaml} | 14 +++- .github/workflows/website-deploy.yaml | 57 --------------- 4 files changed, 80 insertions(+), 76 deletions(-) delete mode 100644 .github/actions/rust-cache/action.yaml create mode 100644 .github/workflows/test-and-deploy.yaml rename .github/workflows/{cargo-test.yaml => test.yaml} (54%) delete mode 100644 .github/workflows/website-deploy.yaml diff --git a/.github/actions/rust-cache/action.yaml b/.github/actions/rust-cache/action.yaml deleted file mode 100644 index 4fb428a..0000000 --- a/.github/actions/rust-cache/action.yaml +++ /dev/null @@ -1,16 +0,0 @@ -name: Rust Cache - -runs: - using: "composite" - steps: - - uses: actions/checkout@v2 - - uses: actions/cache@v2 - with: - path: ~/.cargo - key: dot-cargo - restore-keys: dot-cargo - - uses: actions/cache@v2 - with: - path: target - key: target - restore-keys: target \ No newline at end of file diff --git a/.github/workflows/test-and-deploy.yaml b/.github/workflows/test-and-deploy.yaml new file mode 100644 index 0000000..683c4fc --- /dev/null +++ b/.github/workflows/test-and-deploy.yaml @@ -0,0 +1,69 @@ +name: Test and Deploy + +on: + push: + branches: + - main + +jobs: + test: + name: Run cargo test + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - uses: actions/cache@v2 + with: + path: ~/.cargo + key: dot-cargo + restore-keys: dot-cargo + - uses: actions/cache@v2 + with: + path: target + key: target + restore-keys: target + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + + - name: Run cargo test + run: cargo test + + - name: Install wasm-pack + run: | + curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ap-southeast-2 + + - name: Install dependencies + run: | + cd website + npm install + + - name: Build + run: | + cd website + ./build.sh + + - name: Upload to S3 + uses: jakejarvis/s3-sync-action@7ed8b112447abb09f1da74f3466e4194fc7a6311 + with: + args: --acl public-read --follow-symlinks --delete + env: + AWS_S3_BUCKET: valuescript.org + AWS_REGION: ap-southeast-2 + SOURCE_DIR: website/dist + + - name: Invalidate CloudFront distribution + run: | + aws cloudfront create-invalidation --distribution-id E1X5AVTI60MZKN --paths "/*" + env: + AWS_REGION: ap-southeast-2 diff --git a/.github/workflows/cargo-test.yaml b/.github/workflows/test.yaml similarity index 54% rename from .github/workflows/cargo-test.yaml rename to .github/workflows/test.yaml index be175df..7e32cad 100644 --- a/.github/workflows/cargo-test.yaml +++ b/.github/workflows/test.yaml @@ -1,6 +1,6 @@ -name: Cargo Test +name: Test -on: [push, pull_request] +on: [pull_request] jobs: test: @@ -10,7 +10,15 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - - uses: ./.github/actions/rust-cache + - uses: actions/cache@v2 + with: + path: ~/.cargo + restore-keys: pr-dot-cargo + - uses: actions/cache@v2 + with: + path: target + key: pr-target + restore-keys: pr-target - name: Install Rust uses: actions-rs/toolchain@v1 diff --git a/.github/workflows/website-deploy.yaml b/.github/workflows/website-deploy.yaml deleted file mode 100644 index 8489bc5..0000000 --- a/.github/workflows/website-deploy.yaml +++ /dev/null @@ -1,57 +0,0 @@ -name: Build and Deploy Website - -on: - push: - branches: - - main - -jobs: - build-and-deploy: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - uses: ./.github/actions/rust-cache - - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - - name: Install wasm-pack - run: | - curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh - - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v2 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ap-southeast-2 - - - name: Install dependencies - run: | - cd website - npm install - - - name: Build - run: | - cd website - ./build.sh - - - name: Upload to S3 - uses: jakejarvis/s3-sync-action@7ed8b112447abb09f1da74f3466e4194fc7a6311 - with: - args: --acl public-read --follow-symlinks --delete - env: - AWS_S3_BUCKET: valuescript.org - AWS_REGION: ap-southeast-2 - SOURCE_DIR: website/dist - - - name: Invalidate CloudFront distribution - run: | - aws cloudfront create-invalidation --distribution-id E1X5AVTI60MZKN --paths "/*" - env: - AWS_REGION: ap-southeast-2