Skip to content

Commit

Permalink
new: Add automatic release workflow (#188)
Browse files Browse the repository at this point in the history
* Add release workflow

* Use ansible_collections path

* Gendocs

* Fix docs

* Update integration tests workflow

* Update PR test workflow
  • Loading branch information
LBGarber authored Sep 13, 2022
1 parent 8621468 commit 125c2c1
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 35 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/acctest_command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: AccTest Command

on:
issue_comment:
types: [created]
types: [ created ]

jobs:
acctest-command:
Expand All @@ -11,13 +11,13 @@ jobs:
steps:
- name: Generate App Installation Token
id: generate_token
uses: tibdex/github-app-token@v1
uses: tibdex/github-app-token@f717b5ecd4534d3c4df4ce9b5c1c2214f0f7cd06 # pin@v1
with:
app_id: ${{ secrets.DX_ACCTEST_APP_ID }}
private_key: ${{ secrets.DX_ACCTEST_PRIV_KEY }}

- name: Slash Command Dispatch
uses: peter-evans/slash-command-dispatch@v1
uses: peter-evans/slash-command-dispatch@ace7a198016ae74cd286677c7e7f7e266eb18bc4 # pin@v1
env:
TOKEN: ${{ steps.generate_token.outputs.token }}
with:
Expand Down
17 changes: 6 additions & 11 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ on: pull_request
jobs:
run-docs-validation:
runs-on: ubuntu-20.04
defaults:
run:
working-directory: .ansible/collections/ansible_collections/linode/cloud
steps:
- name: checkout repo
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # pin@v2
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # pin@v3
with:
path: .ansible/collections/ansible_collections/linode/cloud

- name: update packages
run: sudo apt-get update -y
Expand All @@ -26,30 +31,20 @@ jobs:
- name: install collection
run: make install

- name: copy other files to installed collection
run: cp -r Makefile template scripts ~/.ansible/collections/ansible_collections/linode/cloud/

# There is not currently a way to set the working directory for subsequent steps
- name: make temp directory
run: mkdir tmp
working-directory: /home/runner/.ansible/collections/ansible_collections/linode/cloud

- name: copy over old readme
run: cp README.md tmp/README.md
working-directory: /home/runner/.ansible/collections/ansible_collections/linode/cloud

- name: generate new docs
run: DOCS_PATH=tmp/docs make gendocs
working-directory: /home/runner/.ansible/collections/ansible_collections/linode/cloud

- name: compare docs
run: diff -r docs tmp/docs
working-directory: /home/runner/.ansible/collections/ansible_collections/linode/cloud

- name: compare README
run: diff -r README.md tmp/README.md
working-directory: /home/runner/.ansible/collections/ansible_collections/linode/cloud

- name: clean up
run: rm -rf tmp
working-directory: /home/runner/.ansible/collections/ansible_collections/linode/cloud
9 changes: 6 additions & 3 deletions .github/workflows/integration-tests-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ jobs:
# Maintainer has commented /acctest on a pull request
integration-fork:
runs-on: ubuntu-latest
defaults:
run:
working-directory: .ansible/collections/ansible_collections/linode/cloud
if:
github.event_name == 'repository_dispatch' &&
github.event.client_payload.slash_command.sha != '' &&
Expand All @@ -29,15 +32,15 @@ jobs:

# Check out merge commit
- name: Checkout PR
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
ref: 'refs/pull/${{ github.event.client_payload.pull_request.number }}/merge'
path: .ansible/collections/ansible_collections/linode/cloud

- run: mkdir -p $COLLECTION_PATH && cp -r . $COLLECTION_PATH && cd $COLLECTION_PATH && make deps && make TEST_ARGS="-v ${{ github.event.client_payload.slash_command.tests }}" test
- run: make deps && make TEST_ARGS="-v ${{ github.event.client_payload.slash_command.tests }}" test
if: ${{ steps.validate-tests.outputs.match == '' }}
env:
LINODE_API_TOKEN: ${{ secrets.DX_LINODE_TOKEN }}
COLLECTION_PATH: ~/.ansible/collections/ansible_collections/linode/cloud

- uses: actions/github-script@v5
id: update-check-run
Expand Down
19 changes: 7 additions & 12 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ on:
jobs:
run-tests:
runs-on: ubuntu-20.04
defaults:
run:
working-directory: .ansible/collections/ansible_collections/linode/cloud
steps:
- name: checkout repo
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # pin@v2
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # pin@v3
with:
path: .ansible/collections/ansible_collections/linode/cloud

- name: update packages
run: sudo apt-get update -y
Expand All @@ -33,20 +38,10 @@ jobs:
- name: install collection
run: make install

- name: copy makefile to installed collection
run: cp Makefile
~/.ansible/collections/ansible_collections/linode/cloud/Makefile

- name: copy tests to installed collection
run: cp -r tests ~/.ansible/collections/ansible_collections/linode/cloud/tests

- name: copy scripts to installed collection
run: cp -r scripts ~/.ansible/collections/ansible_collections/linode/cloud/scripts

- name: replace existing keys
run: rm -rf ~/.ansible/test && mkdir -p ~/.ansible/test && ssh-keygen -m PEM -q -t rsa -N '' -f ~/.ansible/test/id_rsa

- name: run tests
run: cd ~/.ansible/collections/ansible_collections/linode/cloud && make testall
run: make testall
env:
LINODE_API_TOKEN: ${{ secrets.DX_LINODE_TOKEN }}
42 changes: 42 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This GitHub action can publish assets for release when a tag is created.
# Currently its setup to run on any tag that matches the pattern "v*" (ie. v0.1.0).

name: release
on:
workflow_dispatch: null
release:
types: [ published ]
jobs:
galaxyrelease:
runs-on: ubuntu-latest
defaults:
run:
working-directory: .ansible/collections/ansible_collections/linode/cloud
steps:
- name: checkout repo
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # pin@v3
with:
path: .ansible/collections/ansible_collections/linode/cloud

- name: update packages
run: sudo apt-get update -y

- name: install make
run: sudo apt-get install -y build-essential

- name: setup python 3
uses: actions/setup-python@7f80679172b057fc5e90d70d197929d454754a5a # pin@v2
with:
python-version: '3.x'

- name: install dependencies
run: pip3 install -r requirements-dev.txt -r requirements.txt

- name: install ansible dependencies
run: ansible-galaxy collection install amazon.aws:==1.5.1

- name: publish the collection
run: make publish
env:
GALAXY_TOKEN: ${{ secrets.GALAXY_TOKEN }}
COLLECTION_VERSION: ${{ github.event.release.tag_name }}
16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
COLLECTIONS_PATH ?= ~/.ansible/collections
DOCS_PATH ?= docs
COLLECTION_VERSION ?= 0.0.0

TEST_ARGS := -v
INTEGRATION_CONFIG := tests/integration/integration_config.yml

clean:
rm -f *.tar.gz
rm -f *.tar.gz && rm -rf galaxy.yml

build:
python scripts/render_galaxy.py && ansible-galaxy collection build
build: clean gendocs
python scripts/render_galaxy.py $(COLLECTION_VERSION) && ansible-galaxy collection build

install: clean build
publish: build
@if test "$(GALAXY_TOKEN)" = ""; then \
echo "GALAXY_TOKEN must be set"; \
exit 1; \
fi
ansible-galaxy collection publish --token $(GALAXY_TOKEN) *.tar.gz

install: build
ansible-galaxy collection install *.tar.gz --force -p $(COLLECTIONS_PATH)

deps:
Expand Down
5 changes: 3 additions & 2 deletions scripts/render_galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

import jinja2


def main() -> None:
env = jinja2.Environment(loader=jinja2.FileSystemLoader('template'))
tpl = env.get_template('galaxy.template.yml')
output = tpl.render({
'collection_version': sys.argv[1] if len(sys.argv) > 1 else '0.0.0'
'collection_version': sys.argv[1].removeprefix('v') if len(sys.argv) > 1 else '0.0.0'
})

with open('galaxy.yml', 'w') as f:
f.write(output)


if __name__ == '__main__':
main()
main()

0 comments on commit 125c2c1

Please sign in to comment.