Merge pull request #16 from washabstract/ci_dependency_update #4
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 | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
name: Push to ECR | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Docker | |
uses: docker/setup-buildx-action@v1 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: us-west-2 | |
- name: Ensure OpenStates-Core Dependency References Abstract Core Fork | |
run: | | |
sed -i 's|^openstates =.*|openstates = {git = "https://github.com/washabstract/cyclades-openstates-core.git"}|' pyproject.toml | |
- name: Login to Amazon ECR | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Build and push to Amazon ECR | |
env: | |
DOCKER_IMAGE: ${{ secrets.DOCKER_IMAGE }} | |
run: | | |
COMMIT_HASH=$(git rev-parse --short HEAD) | |
docker build --platform linux/amd64 -t $DOCKER_IMAGE:$COMMIT_HASH -f Dockerfile . | |
docker tag $DOCKER_IMAGE:$COMMIT_HASH $DOCKER_IMAGE:latest | |
docker push $DOCKER_IMAGE:$COMMIT_HASH | |
docker push $DOCKER_IMAGE:latest | |
sync_dags: | |
if: github.ref == 'refs/heads/main' | |
needs: build | |
name: Sync DAG with New Image Tag | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.11" | |
- name: Get GitHub App Token | |
uses: actions/create-github-app-token@v1 | |
id: app-token | |
with: | |
app-id: ${{ secrets.APP_ID }} | |
private-key: ${{ secrets.PRIVATE_KEY }} | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
with: | |
repository: "washabstract/artemis" | |
token: ${{ steps.app-token.outputs.token }} | |
ref: main | |
- name: Update .env file | |
run: sed -i '/^CYCLADES_IMAGE_TAG=/d' aws/.env && echo "CYCLADES_IMAGE_TAG=${GITHUB_SHA}" >> aws/.env | |
- name: Configure git | |
run: | | |
git config --global user.name "send-pr.yml workflow" | |
git config --global user.email "<>" | |
- name: Checkout new branch | |
run: git checkout -b update-image-tag-${GITHUB_SHA} | |
- name: Commit the changes | |
run: git commit aws/.env -m "Update CYCLADES_IMAGE_TAG to ${GITHUB_SHA}" | |
- name: Push branch | |
run: git push --force origin update-image-tag-${GITHUB_SHA}:update-image-tag-${GITHUB_SHA} | |
- name: Open PR | |
uses: jwalton/gh-find-current-pr@v1 | |
id: findPr | |
with: | |
state: all | |
- name: Echo PR | |
run: | | |
gh pr create --body "Changes from PR https://github.com/washabstract/cyclades-openstates-scrapers/pull/${PR}" --title "Update CYCLADES_IMAGE_TAG to ${GITHUB_SHA}" | |
if: success() && steps.findPr.outputs.number | |
env: | |
PR: ${{ steps.findPr.outputs.pr }} | |
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} |