use latewt #101
Workflow file for this run
This file contains hidden or 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: APPCD Diff check | |
on: | |
push: | |
branches: | |
- feature/updated_gh_action | |
pull_request: | |
branches: | |
- main | |
jobs: | |
compare-artifacts: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Main Branch | |
uses: actions/checkout@v4 | |
with: | |
ref: main | |
path: main_branch | |
fetch-depth: 1 | |
- name: Login to docker | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin | |
- name: Generate IaC from Main Branch | |
env: | |
APPCD_TOKEN: ${{ secrets.APPCD_TOKEN }} | |
APPCD_URL: ${{ secrets.APPCD_URL }} | |
run: | | |
mkdir -p artifact/main/ | |
docker run --rm \ | |
--workdir=/code \ | |
-e APPCD_TOKEN=$APPCD_TOKEN \ | |
-e APPCD_URL=$APPCD_URL \ | |
-v ./main_branch:/code \ | |
-v ./artifact/main:/artifact/main \ | |
--entrypoint=appcd \ | |
ghcr.io/appcd-dev/appcd-dist/appcd-cli:v0.9.1 \ | |
generate --mode ci --lang Python --output=/artifact/main/.appcd/charts --iac-type Helm | |
cd artifact/main/.appcd/charts | |
ls -latr | |
unzip code.zip && rm code.zip | |
- name: Checkout PR Branch | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.head_ref }} | |
path: pr_branch | |
fetch-depth: 1 | |
- name: Extract branch name | |
id: extract_branch | |
run: echo "branch=$(basename ${{ github.head_ref}})" >> $GITHUB_OUTPUT | |
- name: echo branch name | |
run: echo ${{ steps.extract_branch.outputs.branch }} | |
- name: Generate IaC from PR branch | |
env: | |
APPCD_TOKEN: ${{ secrets.APPCD_TOKEN }} | |
APPCD_URL: ${{ secrets.APPCD_URL }} | |
run: | | |
docker pull ghcr.io/appcd-dev/appcd-dist/appcd-cli:v0.9.0 | |
mkdir -p artifact/${{ steps.extract_branch.outputs.branch }}/ | |
docker run --rm \ | |
--workdir=/code \ | |
-v ./pr_branch/:/code \ | |
-v ./artifact/${{ steps.extract_branch.outputs.branch }}:/artifact/${{ steps.extract_branch.outputs.branch }} \ | |
-e APPCD_TOKEN=$APPCD_TOKEN \ | |
-e APPCD_URL=$APPCD_URL \ | |
--entrypoint=appcd \ | |
ghcr.io/appcd-dev/appcd-dist/appcd-cli:v0.9.1 \ | |
generate --mode ci --lang Python --iac-type Helm --output=/artifact/${{ steps.extract_branch.outputs.branch }}/.appcd/charts | |
cd artifact/${{ steps.extract_branch.outputs.branch }}/.appcd/charts | |
unzip code.zip && rm code.zip | |
- name: Copy infrastructure files if empty | |
run: | | |
cd pr_branch | |
mkdir -p infrastructure | |
if [ -z "$(ls -A infrastructure/)" ]; then | |
cp -r .appcd/infrastructure/app/rds/ infrastructure/ | |
git config --local user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
git add infrastructure/ | |
git commit -m "Adds IaC dependency files" | |
git push | |
fi | |
- name: Generate diff between Main and PR branch | |
run: | | |
mkdir -p pr_branch/deployment_files | |
mv ./artifact/main/.appcd pr_branch/deployment_files/ | |
cd pr_branch | |
git config --local user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
git add deployment_files | |
git commit -m "staging deployment files from main to compare them" | |
rm -rf deploment_files/* | |
rm -rf deployment_files/.appcd | |
cd .. | |
mv artifact/${{ steps.extract_branch.outputs.branch }}/.appcd pr_branch/deployment_files/ | |
cd pr_branch | |
git diff --output=../diff.txt deployment_files/ | cat | |
cat ../diff.txt | |
- name: Comment PR with IaC Changes | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const fs = require('fs'); | |
const diff = fs.readFileSync('diff.txt', 'utf-8'); | |
const body = `### AppCD Diff:\n\`\`\`${diff}\`\`\``; | |
await github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: body | |
}) | |
- name: Trigger atlantis plan | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const fs = require('fs'); | |
const body = `atlantis plan`; | |
await github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: body | |
}) |