-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from cisagov/improvement/actions
Migrate CI system and Docker Hub organization
- Loading branch information
Showing
7 changed files
with
170 additions
and
79 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
--- | ||
name: build | ||
|
||
on: [push] | ||
|
||
env: | ||
IMAGE_NAME: cisagov/example | ||
PIP_CACHE_DIR: ~/.cache/pip | ||
PRE_COMMIT_CACHE_DIR: ~/.cache/pre-commit | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.7 | ||
- name: Cache pip test requirements | ||
uses: actions/cache@v1 | ||
with: | ||
path: ${{ env.PIP_CACHE_DIR }} | ||
key: "${{ runner.os }}-pip-test-\ | ||
${{ hashFiles('**/requirements-test.txt') }}" | ||
restore-keys: | | ||
${{ runner.os }}-pip-test- | ||
${{ runner.os }}-pip- | ||
- name: Cache pre-commit hooks | ||
uses: actions/cache@v1 | ||
with: | ||
path: ${{ env.PRE_COMMIT_CACHE_DIR }} | ||
key: "${{ runner.os }}-pre-commit-\ | ||
${{ hashFiles('**/.pre-commit-config.yaml') }}" | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install --upgrade -r requirements-test.txt | ||
- name: Run linters on all files | ||
run: pre-commit run --all-files | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: Determine image version | ||
id: get_ver | ||
run: | | ||
echo "##[set-output name=version;]$(./bump_version.sh show)" | ||
- name: Build docker image | ||
run: | | ||
version=$(./bump_version.sh show) | ||
docker build \ | ||
--tag "$IMAGE_NAME" \ | ||
--build-arg GIT_COMMIT=$(git log -1 --format=%H) \ | ||
--build-arg GIT_REMOTE=$(git remote get-url origin) \ | ||
--build-arg VERSION=${{ steps.get_ver.outputs.version }} \ | ||
. | ||
- name: Save docker image artifact | ||
run: | | ||
mkdir dist | ||
version=$(./bump_version.sh show) | ||
docker save $IMAGE_NAME:latest | gzip > dist/image.tar.gz | ||
- name: Upload artifacts | ||
uses: actions/upload-artifact@v1 | ||
with: | ||
name: dist | ||
path: dist | ||
test: | ||
runs-on: ubuntu-latest | ||
needs: [build] | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.7 | ||
- name: Cache pip test requirements | ||
uses: actions/cache@v1 | ||
with: | ||
path: ${{ env.PIP_CACHE_DIR }} | ||
key: "${{ runner.os }}-pip-test-\ | ||
${{ hashFiles('**/requirements-test.txt') }}" | ||
restore-keys: | | ||
${{ runner.os }}-pip-test- | ||
${{ runner.os }}-pip- | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install --upgrade -r requirements-test.txt | ||
- name: Download docker image artifact | ||
uses: actions/download-artifact@v1 | ||
with: | ||
name: dist | ||
- name: Load docker image | ||
run: docker load < dist/image.tar.gz | ||
- name: Run tests | ||
run: pytest |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
--- | ||
name: release | ||
|
||
on: | ||
release: | ||
types: [prereleased, released] | ||
|
||
env: | ||
IMAGE_NAME: cisagov/example | ||
DOCKER_PW: ${{ secrets.DOCKER_PW }} | ||
DOCKER_USER: ${{ secrets.DOCKER_USER }} | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.7 | ||
- name: Determine image version | ||
id: get_ver | ||
run: | | ||
echo "##[set-output name=version;]$(./bump_version.sh show)" | ||
- name: Build Docker image | ||
run: | | ||
docker build \ | ||
--tag "$IMAGE_NAME" \ | ||
--build-arg GIT_COMMIT=$(git log -1 --format=%H) \ | ||
--build-arg GIT_REMOTE=$(git remote get-url origin) \ | ||
--build-arg VERSION=${{ steps.get_ver.outputs.version }} \ | ||
. | ||
- name: Tag Docker image | ||
run: | | ||
IFS='.' read -r -a version_array \ | ||
<<< "${{ steps.get_ver.outputs.version }}" | ||
docker login --username "$DOCKER_USER" --password "$DOCKER_PW" | ||
docker tag "$IMAGE_NAME" "${IMAGE_NAME}:latest" | ||
docker tag "$IMAGE_NAME" \ | ||
"${IMAGE_NAME}:${{ steps.get_ver.outputs.version }}" | ||
docker tag "$IMAGE_NAME" \ | ||
"${IMAGE_NAME}:${version_array[0]}.${version_array[1]}" | ||
docker tag "$IMAGE_NAME" "${IMAGE_NAME}:${version_array[0]}" | ||
- name: Publish image to Docker Hub | ||
run: | | ||
IFS='.' read -r -a version_array \ | ||
<<< "${{ steps.get_ver.outputs.version }}" | ||
docker push "${IMAGE_NAME}:latest" | ||
docker push "${IMAGE_NAME}:${{ steps.get_ver.outputs.version }}" | ||
docker push "${IMAGE_NAME}:${version_array[0]}.${version_array[1]}" | ||
docker push "${IMAGE_NAME}:${version_array[0]}" | ||
- name: Publish README.md to Docker Hub | ||
run: ./push_readme.sh |
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
This file was deleted.
Oops, something went wrong.
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
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
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