Merge pull request #66 from shield-auth/develop #94
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Rust CI/CD | |
on: | |
push: | |
branches: ["trunk"] | |
env: | |
CARGO_TERM_COLOR: always | |
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} | |
IMAGE_NAME: "shieldauth/shield" | |
CIRCLECI_TOKEN: ${{ secrets.CIRCLECI_TOKEN }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Check CircleCI Build Status | |
run: | | |
# Loop to check CircleCI build status until it is complete | |
while : ; do | |
CIRCLECI_STATUS=$(curl -s -u ${CIRCLECI_TOKEN}: \ | |
"https://circleci.com/api/v2/project/github/shield-auth/shield/pipeline?branch=trunk" | \ | |
jq -r '.items[0].state') | |
# If status is running, wait and check again in 30 seconds | |
if [ "$CIRCLECI_STATUS" == "running" ]; then | |
echo "CircleCI build is still running. Waiting for 30 seconds..." | |
sleep 30 | |
continue | |
fi | |
# If status is failed, exit | |
if [ "$CIRCLECI_STATUS" == "failed" ]; then | |
echo "CircleCI build failed. Exiting." | |
exit 1 | |
fi | |
# If status is successful, proceed | |
if [ "$CIRCLECI_STATUS" == "success" ]; then | |
echo "CircleCI build passed. Proceeding with Docker build and push." | |
break | |
fi | |
# If status is unknown, exit | |
if [ -z "$CIRCLECI_STATUS" ]; then | |
echo "Unable to determine CircleCI build status. Exiting." | |
exit 1 | |
fi | |
done | |
- name: Build the project | |
run: cargo build --verbose | |
- name: Run tests | |
run: cargo test --verbose | |
- name: Log in to DockerHub | |
run: echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin | |
- name: Build Docker image | |
run: docker build -t $IMAGE_NAME:${{ github.sha }} . | |
- name: Push Docker image to DockerHub | |
run: | | |
docker tag $IMAGE_NAME:${{ github.sha }} $IMAGE_NAME:latest | |
docker push $IMAGE_NAME:${{ github.sha }} | |
docker push $IMAGE_NAME:latest |