Adjust branch in pipeline #1
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: CI/CD Pipeline | |
on: | |
push: | |
branches: | |
- master | |
release: | |
types: | |
- published | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '21' | |
distribution: 'adopt' | |
- name: Cache Gradle dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ~/.gradle/caches | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Gradle clean build | |
run: ./gradlew clean build | |
- name: Set Docker tags based on branch or release | |
id: set-tag | |
run: | | |
if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then | |
echo "DOCKER_TAG_STAGE=devinfritz/vzbot-discordbot:stage-${GITHUB_SHA}" >> $GITHUB_ENV | |
echo "DOCKER_TAG_STAGE_LATEST=devinfritz/vzbot-discordbot:stage-latest" >> $GITHUB_ENV | |
echo "DEPLOY_ENV=stage" >> $GITHUB_ENV | |
elif [[ "${GITHUB_EVENT_NAME}" == "release" ]]; then | |
RELEASE_VERSION=${{ github.event.release.tag_name }} | |
echo "DOCKER_TAG_PROD=devinfritz/vzbot-discordbot:production-${GITHUB_SHA}" >> $GITHUB_ENV | |
echo "DOCKER_TAG_PROD_LATEST=devinfritz/vzbot-discordbot:production-latest" >> $GITHUB_ENV | |
echo "DEPLOY_ENV=production" >> $GITHUB_ENV | |
fi | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build and push Docker images | |
run: | | |
if [[ "$DEPLOY_ENV" == "stage" ]]; then | |
docker buildx build --platform linux/amd64,linux/arm64 \ | |
-t ${DOCKER_TAG_STAGE} -t ${DOCKER_TAG_STAGE_LATEST} --push . | |
elif [[ "$DEPLOY_ENV" == "production" ]]; then | |
docker buildx build --platform linux/amd64,linux/arm64 \ | |
-t ${DOCKER_TAG_PROD} -t ${DOCKER_TAG_PROD_LATEST} --push . | |
fi | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build-and-push | |
steps: | |
- name: Execute remote SSH commands | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.SERVER_HOST }} | |
username: github | |
password: ${{ secrets.SERVER_PASSWORD }} | |
port: ${{ secrets.SERVER_SSH_PORT }} | |
script: | | |
if [[ "$DEPLOY_ENV" == "stage" ]]; then | |
./deploy.sh stage | |
elif [[ "$DEPLOY_ENV" == "production" ]]; then | |
./deploy.sh production | |
fi |