Skip to content

Merge pull request #2 from MatthewC/dependabot/go_modules/gopkg.in/ya… #41

Merge pull request #2 from MatthewC/dependabot/go_modules/gopkg.in/ya…

Merge pull request #2 from MatthewC/dependabot/go_modules/gopkg.in/ya… #41

Workflow file for this run

name: CI/CD
on: [push]
jobs:
test:
runs-on: ubuntu-latest
name: Test CopyCat
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Test CopyCat
run: go test -v ./...
env:
DUMMY_HOST: ${{ secrets.TESTING_HOST }}
DUMMY_KEY: ${{ secrets.TESTING_KEY }}
DUMMY_SECRET: ${{ secrets.TESTING_SECRET }}
DUMMY_BUCKET: ${{ secrets.TESTING_BUCKET }}
DUMMY_REGION: ${{ secrets.TESTING_REGION }}
conditional_check:
runs-on: ubuntu-latest
name: Conditional check
outputs:
src_changed: ${{ steps.check_src_changed.outputs.src_changed }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Check for source file changes
shell: pwsh
id: check_src_changed
run: |
# Diff HEAD with the previous commit
$diff = git diff --name-only HEAD^ HEAD
# Check if a go file has changed (added, modified, deleted)
$SourceDiff = $diff | Where-Object { $_ -match '.go$' }
$HasDiff = $SourceDiff.Length -gt 0
echo $HasDiff
echo "src_changed=$HasDiff" >> $GITHUB_OUTPUT
build:
runs-on: ubuntu-latest
needs: [test]
name: Build binaries
if: ${{ needs.conditional_check.outputs.src_changed }} == 'True'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Build CopyCat
run: |
make build-all
env:
VERSION_LOG: ${{ secrets.COPYCAT_VERSION_PATH }}
VERSION_HOST: ${{ secrets.COPYCAT_VERSION_HOST }}
- name: Set version tag
run: go run ./... version-clean > CURRENT_VERSION
- name: Archive build
uses: actions/upload-artifact@v3
with:
name: copycat-release
path: |
bin
CURRENT_VERSION
deploy:
runs-on: ubuntu-latest
needs: [build]
name: Deploy CopyCat
if: ${{ needs.conditional_check.outputs.src_changed }} == 'True'
steps:
- name: Download copycat build
uses: actions/download-artifact@v3
with:
name: copycat-release
- name: Deploy to S3
run: |
old_version=$(cat CURRENT_VERSION)
aws s3 --recursive mv ${{ secrets.AWS_ROOT_BUCKET }}/latest/ ${{ secrets.AWS_ROOT_BUCKET }}/${old_version}/
aws s3 mv ${{ secrets.AWS_ROOT_BUCKET }}/CURRENT_VERSION ${{ secrets.AWS_ROOT_BUCKET }}/${old_version}/
aws s3 sync ./bin ${{ secrets.AWS_ROOT_BUCKET }}/latest/
aws s3 cp CURRENT_VERSION ${{ secrets.AWS_ROOT_BUCKET }}/
aws s3api put-object-tagging --bucket ${{ secrets.AWS_BUCKET_NAME }} --key ${{ secrets.AWS_ROOT_PATH }}/CURRENT_VERSION --tagging ${{ secrets.AWS_OBJECT_TAGGING }}
aws s3api list-objects --bucket ${{ secrets.AWS_BUCKET_NAME }} --query 'Contents[].{Key:Key}' --prefix ${{ secrets.AWS_ROOT_PATH }}/latest --output text | xargs -n 1 aws s3api put-object-tagging --bucket ${{ secrets.AWS_BUCKET_NAME }} --tagging ${{ secrets.AWS_OBJECT_TAGGING }} --key
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
VERSION_LOG: ${{ secrets.DEPLOY_VERS_LOG }}
VERSION_HOST: ${{ secrets.DEPLOY_VERS_HOST }}