-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (124 loc) · 4.09 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
---
name: Release to Ansible Galaxy
on:
workflow_dispatch:
# Not needed anymore, since branch protection
#push:
# branches: ["main"]
# The branches below must be a subset of the branches above
#pull_request:
# branches: [ "main" ]
jobs:
lint:
name: Ansible Lint
runs-on: ubuntu-latest
steps:
- name: Which branch?
shell: bash
run: |
echo "${{ github.head_ref || github.ref_name }}"
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref_name }}
# step to install prerequis
- name: Install prerequis
shell: bash
run: |
make prerequis
- name: Run ansible-lint
uses: ansible/ansible-lint@main
update-version:
name: Update Versions
needs: lint
runs-on: ubuntu-latest
if: github.repository == 'mozebaltyk/rkub'
permissions:
actions: write
checks: write
contents: write
steps:
# Checkout on branch where pull request
- name: Which branch?
shell: bash
run: |
echo "${{ github.head_ref || github.ref_name }}"
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref_name }}
# This one is redondant with renovate but make sure
# that all versions are updated before to release!
- name: Update version in readme and changelog
uses: ./.github/actions/update-version
release:
name: Release to Galaxy
needs: update-version
runs-on: ubuntu-latest
if: github.repository == 'mozebaltyk/rkub'
permissions:
actions: write
checks: write
contents: write
deployments: write
packages: write
pages: write
outputs:
tag_version: ${{ steps.get_version.outputs.TAG_VERSION }}
steps:
# Release
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- run: git pull
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: 'pip'
cache-dependency-path: '**/ee-requirements.txt'
- name: Get current version
id: get_version
run: echo "TAG_VERSION=$(yq -r .version galaxy.yml)" >> $GITHUB_OUTPUT
- name: Check if tag exists
id: check_tag
run: echo "TAG_EXISTS=$(git tag | grep ${{ steps.get_version.outputs.TAG_VERSION }})" >> $GITHUB_OUTPUT
- name: Fail if tag exists
env:
tag_version: ${{ steps.get_version.outputs.TAG_VERSION }}
tag_exists: ${{ steps.check_tag.outputs.TAG_EXISTS }}
if: ${{ steps.get_version.outputs.TAG_VERSION == steps.check_tag.outputs.TAG_EXISTS }}
uses: actions/github-script@v7
with:
script: |
core.setFailed('Release tag already exists in git (tag_exists var: ${tag_exists} and tag_version: ${tag_version})')
# Build and push to Galaxy
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ansible-core antsibull
sudo apt --fix-missing update
sudo apt install -y sed hub
- name: Build collection
run: |
ansible-galaxy collection build .
- name: Publish collection
env:
ANSIBLE_GALAXY_API_KEY: ${{ secrets.ANSIBLE_GALAXY_API_KEY }}
run: |
ansible-galaxy collection publish *.tar.gz --api-key $ANSIBLE_GALAXY_API_KEY
# GH tag and release
- name: Create release tag
run: |
git config user.name github-actions
git config user.email [email protected]
git tag -a ${{ steps.get_version.outputs.TAG_VERSION }} -m "$(cat CHANGELOG.md)" || echo "No changes to commit"
git push origin --tags
- name: Publish Release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.TAG_VERSION }}
files: "*.tar.gz"
body_path: CHANGELOG.md