-
Notifications
You must be signed in to change notification settings - Fork 1
163 lines (157 loc) · 6.21 KB
/
snapshot.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
name: Push snapshot to Github Pages
on:
workflow_run:
workflows: [Build and Test Project]
types: [completed]
branches: [master]
jobs:
verify:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success'}}
steps:
- uses: actions/checkout@v4
- name: Set Up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Install Dependencies
run: sudo apt-get install -y pandoc
- name: Build snapshot
run: mvn verify -Pbuild-snapshot
- name: Upload p2 repo artifact
uses: actions/upload-artifact@v3
with:
name: p2-artifact
path: ${{ github.workspace }}/com.rockwellcollins.atc.resolute.site/target/repository/
publish:
runs-on: ubuntu-latest
needs: verify
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Install Eclipse
run: sudo snap install --classic eclipse
- name: Checkout current update site
uses: actions/checkout@v4
with:
repository: loonwerks/Resolute-Updates
path: Resolute-Updates
ssh-key: ${{ secrets.DEPLOY_KEY }}
persist-credentials: true
- name: Download p2 repo artifact
uses: actions/download-artifact@v3
with:
name: p2-artifact
path: ${{ github.workspace }}/p2-artifact
- name: Parse version number
run: echo "SNAPSHOT_VERSION=$(ls ${{ github.workspace }}/p2-artifact/features/com.rockwellcollins.atc.resolute.feature_*.jar | grep -o "[0-9]\\+\\.[0-9]\\+\\.[0-9]\\+\\.[0-9]\\{12\\}")" >> $GITHUB_ENV
- name: Rename p2-artifact and move to snapshot directory
run: |
mv ${{ github.workspace }}/p2-artifact ${{ github.workspace }}/${{ env.SNAPSHOT_VERSION }}
mkdir -p ${{ github.workspace }}/Resolute-Updates/snapshots
mv ${{ github.workspace }}/${{ env.SNAPSHOT_VERSION }} ${{ github.workspace }}/Resolute-Updates/snapshots
- name: Build with Ant
run: java -jar $(find /snap/eclipse -name org.eclipse.equinox.launcher_*.jar) -application org.eclipse.ant.core.antRunner -buildfile ${{ github.workspace }}/com.rockwellcollins.atc.resolute.site/packaging-p2composite.ant p2.composite.add.snapshot -Dcomposite.base.dir=${{ github.workspace }}/Resolute-Updates -Dfull.version=${{ env.SNAPSHOT_VERSION }}
- name: Push new snapshot to Resolute-Updates
run: |
cd Resolute-Updates
git config --global user.name 'GitHub Actions'
git config --global user.email '[email protected]'
git add .
git commit -m 'Snapshot ${{ env.SNAPSHOT_VERSION }}'
git push
find_snapshots_to_delete:
runs-on: ubuntu-latest
needs: publish
outputs:
delete_snapshots: ${{ steps.python_script.outputs.delete_snapshots }}
matrix: ${{ steps.python_script.outputs.snapshots_to_delete }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set Up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Checkout current update site
uses: actions/checkout@v4
with:
repository: loonwerks/Resolute-Updates
path: Resolute-Updates
- name: Install GitPython
run: pip install GitPython
- name: Run python script
uses: jannekem/run-python-script-action@v1
id: python_script
with:
script: |
import os
import git
import json
repo = git.Repo(os.getcwd())
tags = str(repo.tags).split(",")
path = os.path.join(os.getcwd(), "Resolute-Updates/snapshots")
snapshots = sorted([f for f in os.listdir(path) if os.path.isdir(os.path.join(path, f))])
snapshots_to_delete = list()
for i in range(len(snapshots)-10):
tag_protected = False
for tag in tags:
tag = tag[tag.find("\"refs/tags/")+11:tag.rfind("\"")]
if (snapshots[i] + "-SNAPSHOT") == tag:
tag_protected = True
break
if not tag_protected:
set_output("delete_snapshots", "true")
snapshots_to_delete.append(snapshots[i])
set_output("snapshots_to_delete", json.dumps(snapshots_to_delete))
delete_snapshots:
runs-on: ubuntu-latest
needs: find_snapshots_to_delete
if: ${{ needs.find_snapshots_to_delete.outputs.delete_snapshots == 'true' }}
strategy:
matrix:
version: ${{ fromJson(needs.find_snapshots_to_delete.outputs.matrix) }}
max-parallel: 1
steps:
- uses: actions/checkout@v4
- name: Set Up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Install Eclipse
run: sudo snap install --classic eclipse
- name: Checkout current update site
uses: actions/checkout@v4
with:
repository: loonwerks/Resolute-Updates
path: Resolute-Updates
ssh-key: ${{ secrets.DEPLOY_KEY }}
persist-credentials: true
- name: Install git filter repo
run: sudo apt-get install git-filter-repo
- name: Push changes to git
run: |
cd Resolute-Updates
git config --global user.name 'GitHub Actions'
git config --global user.email '[email protected]'
java -jar $(find /snap/eclipse -name org.eclipse.equinox.launcher_*.jar) -application org.eclipse.ant.core.antRunner -buildfile ${{ github.workspace }}/com.rockwellcollins.atc.resolute.site/packaging-p2composite.ant p2.composite.remove.snapshot -Dcomposite.base.dir=${{ github.workspace }}/Resolute-Updates -Dfull.version=${{ matrix.version }}
git add .
git commit -m 'Delete Snapshot ${{ matrix.version }}'
git push
git filter-repo --invert-paths --path snapshots/${{ matrix.version }} --force
git remote add origin [email protected]:loonwerks/Resolute-Updates
git push origin --force --all