Skip to content

Commit

Permalink
fix: split workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
kameshsampath committed Jul 19, 2021
1 parent 2fa3917 commit a59d7e5
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 95 deletions.
101 changes: 101 additions & 0 deletions .github/workflows/release-collection.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Ansible Galaxy Collection

on:
release:
types:
- released
workflow_dispatch:

jobs:
attach-collection-artifacts:
runs-on: ubuntu-latest
env:
DIST_DIR: dist
strategy:
matrix:
python-version:
- 3.8
steps:
- uses: actions/checkout@v2
with:
ref: "${{ github.event.ref }}"

- name: Setup python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install Poetry
uses: snok/[email protected]
with:
virtualenvs-create: true
virtualenvs-in-project: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
with:
path: .venv
key: ${{ runner.os }}-venv-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
run: poetry install
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'

- name: Build the Ansible Collections tarball
id: build-collection
run: |
poetry env use python
poetry run ansible-galaxy collection build --out $DIST_OUT_DIR
env:
DIST_OUT_DIR: "${{ github.workspace }}/${{ env.DIST_DIR }}"

- name: Extract Release Semantic Version
id: collection-info
env:
GALAXY_VERSION: "${{ github.event.release.tag_name }}"
run: |
echo "::set-output name=galaxy_version::${GALAXY_VERSION#*v}"
echo "::set-output name=collection_tarfile::kameshsampath-kubernetes_spices-${GALAXY_VERSION#*v}.tar.gz"
- name: "Attach Artifacts to Release"
uses: actions/[email protected]
env:
TAG_NAME: ${{ github.event.release.tag_name }}
ASSET_NAME: "kameshsampath-kubernetes_spices-${{ steps.collection-info.outputs.galaxy_version }}"
ASSET_FILE: "${{ github.workspace }}/${{ env.DIST_DIR }}/${{ steps.collection-info.outputs.collection_tarfile }}"
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs')
const {TAG_NAME} = process.env
const {ASSET_FILE} = process.env
const {ASSET_NAME} = process.env
const {payload} = context
const owner = payload.repository.owner.login
const repo = payload.repository.name
// console.log("Context Repository %s and Owner is %s",repo,owner)
const { data } = await github.request(`GET /repos/${owner}/${repo}/releases/tags/{tag}`, {
tag: TAG_NAME
}).catch(err => {
console.error("Error getting release %s", JSON.stringify(err.errors))
})
const upload_url = data.upload_url
const uploadAsset = await github.request({
method: "POST",
url: upload_url,
name: `${ASSET_NAME}.tar.gz`,
headers: {
"content-type": "application/tar+gzip",
},
data: fs.readFileSync(ASSET_FILE)
}).catch(err => {
console.log("Error uploading asset %s", err)
})
console.log("Asset upload --> %s ",uploadAsset)
96 changes: 1 addition & 95 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release Artifacts
name: Ansible Runner

on:
release:
Expand All @@ -7,100 +7,6 @@ on:
workflow_dispatch:

jobs:
attach-collection-artifacts:
runs-on: ubuntu-latest
env:
DIST_DIR: dist
strategy:
matrix:
python-version:
- 3.8
steps:
- uses: actions/checkout@v2
with:
ref: "${{ github.event.ref }}"

- name: Setup python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install Poetry
uses: snok/[email protected]
with:
virtualenvs-create: true
virtualenvs-in-project: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v2
with:
path: .venv
key: ${{ runner.os }}-venv-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
run: poetry install
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'

- name: Build the Ansible Collections tarball
id: build-collection
run: |
poetry env use python
poetry run ansible-galaxy collection build --out $DIST_OUT_DIR
env:
DIST_OUT_DIR: "${{ github.workspace }}/${{ env.DIST_DIR }}"

- name: Extract Release Semantic Version
id: collection-info
env:
GALAXY_VERSION: "${{ github.event.release.tag_name }}"
run: |
echo "::set-output name=galaxy_version::${GALAXY_VERSION#*v}"
echo "::set-output name=collection_tarfile::kameshsampath-kubernetes_spices-${GALAXY_VERSION#*v}.tar.gz"
- name: "Attach Artifacts to Release"
uses: actions/[email protected]
env:
TAG_NAME: ${{ github.event.release.tag_name }}
ASSET_NAME: "kameshsampath-kubernetes_spices-${{ steps.collection-version.outputs.galaxy_version }}"
ASSET_FILE: "${{ github.workspace }}/${{ env.DIST_DIR }}/${{ steps.collection-version.outputs.collection_tarfile }}"
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs')
const {TAG_NAME} = process.env
const {ASSET_FILE} = process.env
const {ASSET_NAME} = process.env
const {payload} = context
const owner = payload.repository.owner.login
const repo = payload.repository.name
// console.log("Context Repository %s and Owner is %s",repo,owner)
const { data } = await github.request(`GET /repos/${owner}/${repo}/releases/tags/{tag}`, {
tag: TAG_NAME
}).catch(err => {
console.error("Error getting release %s", JSON.stringify(err.errors))
})
const upload_url = data.upload_url
const uploadAsset = await github.request({
method: "POST",
url: upload_url,
name: `${ASSET_NAME}.tar.gz`,
headers: {
"content-type": "application/zip",
},
data: fs.readFileSync(ASSET_FILE)
}).catch(err => {
console.log("Error uploading asset %s", err)
})
console.log("Asset upload --> %s ",uploadAsset)
ansible-builder-ee:
runs-on: ubuntu-latest
env:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![Release Artifacts](https://github.com/kameshsampath/kubernetes_spices/actions/workflows/release.yml/badge.svg)](https://github.com/kameshsampath/kubernetes_spices/actions/workflows/release.yml)
[![Dev Ansible EE Image](https://github.com/kameshsampath/kubernetes_spices/actions/workflows/dev-image.yaml/badge.svg)](https://github.com/kameshsampath/kubernetes_spices/actions/workflows/dev-image.yaml)
[![Documentation](https://github.com/kameshsampath/kubernetes_spices/actions/workflows/site.yml/badge.svg)](https://github.com/kameshsampath/kubernetes_spices/actions/workflows/site.yml)

The [Ansible collection](https://docs.ansible.com/ansible/latest/user_guide/collections_using.html) that can help in setting up Kubernetes cluster such as [KinD](https://kind.sigs.k8s.io) or deploy components to existing Kubernetes cluster.

Expand Down

0 comments on commit a59d7e5

Please sign in to comment.